Add an SSH Key to GitHub
Generate, Configure, and Use SSH Keys for Seamless Git Operations
If you are working with Git and GitHub, using SSH keys for authentication is a secure and convenient way to push and pull code from your repositories without having to enter your username and password every time.
In this guide, I will walk you through the entire process of generating an SSH key on a Linux machine and adding it to your GitHub account. Whether you are setting up a new machine or improving your workflow, this guide is for you.
What is an SSH Key and Why Use It?
SSH (Secure Shell) keys are a pair of cryptographic keys used to authenticate secure connections between your computer and remote servers (like GitHub).
Benefits of using SSH with GitHub:
Secure: Keys are more secure than using passwords.
Convenient: Once set up, you won’t need to enter your GitHub credentials for each Git operation.
Required: GitHub now requires SSH (or PATs) for operations involving remote repositories.
Step 1: Generate an SSH Key on Your Linux Machine
Open a terminal on your Linux machine and enter the following command:
ssh-keygen -t ed25519 -C "your_username@company_domain.com"Explanation of the command:
ssh-keygen: The command to generate a new SSH key.-t ed25519: Specifies the type of key to create.ed25519is a modern, secure algorithm recommended by GitHub.-C "your_username@company_domain.com": Adds a comment (usually your email) to the key to identify it later.
You will be prompted to choose a file to save the key:
Enter file in which to save the key (/home/your_user/.ssh/id_ed25519):What to do here:
Press Enter to accept the default location (
~/.ssh/id_ed25519).Next, you’ll be asked for a passphrase. This adds an extra layer of security.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:You can press Enter twice to skip setting a passphrase if you want passwordless authentication.
Once complete, you’ll see output like this:
Your identification has been saved in /home/your_user/.ssh/id_ed25519
Your public key has been saved in /home/your_user/.ssh/id_ed25519.pubStep 2: Copy the Public Key
Now you need to copy your public key so you can add it to GitHub.
Run this command to display your public key:
cat ~/.ssh/id_ed25519.pubThis will output something like:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC34xF0Y83a3JL7eJ4DndyT4KzVtqZ8o8uPOd4NmLd9G your_username@company_domain.comSelect the entire string and copy it to your clipboard. Make sure not to add extra spaces or line breaks when copying.
Step 3: Add the SSH Key to Your GitHub Account
Now, let’s add your key to GitHub:
Log in to your GitHub account.
In the top-right corner, click on your profile picture and then Settings.
In the sidebar, click on SSH and GPG keys.
Click the green New SSH key button.
Fill out the form:
Title: Give your key a meaningful name (e.g.,
Spare laptop,Work Desktop,Ubuntu VM).Key: Paste the SSH key you copied earlier.
Click Add SSH key to save.
You may be prompted to confirm your GitHub password for security.
🎉 Success! You’re now connected to GitHub via SSH.
