Introduction
In this guide, you’ll learn how to generate an SSH key and set it up with GitHub. SSH keys provide a secure way to access GitHub without needing to repeatedly enter your password, making your workflow faster and more secure.
Solution
Generate a new SSH key
To generate a new SSH key, run the following command in your terminal:
ssh-keygen -t ed25519 -C "any comment"
This command uses the ed25519 algorithm, which is considered both secure and efficient. Replace "any comment" with something descriptive, like your email or a short label.
This comment will help you identify your key later, especially if you manage multiple SSH keys.
Output
Enter file
You’ll be prompted to choose where to save the key file. By default, the SSH key is saved in the ~/.ssh
directory with a generic name like id_ed25519
.
If you’d like to name the key something else (e.g., pop_os_athanasius), you can enter the file path here.
If you want to keep it as the default, simply press Enter.
In this example, we’ll name it /home/athanasius/.ssh/pop_os_athanasius.
Output
Enter passphrase
You’ll be prompted to enter a passphrase to protect your key. Using a passphrase is recommended for added security.
However, if you prefer to leave it blank, just press Enter twice. Keep in mind that without a passphrase, anyone with access to your machine can use this key.
In this example, we’ll leave it blank for simplicity.
Output
Verify the key generation
Once the key generation process is complete, you should see a confirmation message showing the key’s fingerprint. This unique identifier verifies the key was created successfully.
View the public key
To connect your SSH key with GitHub, you’ll need to add the public key to your GitHub account. To display your public key in the terminal, run:
cat ./.ssh/pop_os_athanasius.pub
Adding the SSH Key to GitHub
With your SSH key ready, it’s time to add it to GitHub for secure access.
Access GitHub Settings
Navigate to GitHub, log in, and go to Settings. You can find this option in the drop-down menu under your profile icon.
Open the SSH and GPG Keys Section
In the Settings menu, find and click on SSH and GPG keys from the sidebar. This section is where you’ll add new SSH keys to your GitHub account.
Add a New SSH Key
Click New SSH key. You’ll be prompted to enter a title and paste your key.
Save the key
Click Add SSH key to save it to your GitHub account. You may be prompted to confirm this action with your GitHub password.
Check connection
With your key added, let’s test the connection to GitHub. This step verifies that everything is configured correctly.
Run the following command:
ssh -T git@github.com
The first time you connect to GitHub via SSH, you may see a message like this:
The authenticity of host 'github.com (20.201.28.151)' can't be established.
ED25519 key fingerprint is SHA256:+AiB3wcvD6FuJGhblZimn/zMBA0zZNSvHakb4evDOkU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Type yes
The authenticity of host 'github.com (20.201.28.151)' can't be established.
ED25519 key fingerprint is SHA256:+AiB3wcvD6FuJGhblZimn/zMBA0zZNSvHakb4evDOkU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
Hi alexcalaca! You've successfully authenticated, but GitHub does not provide shell access.
Type yes and press Enter to continue. GitHub will now be added to your list of known hosts.
Success
If you see the message confirming your authentication, congratulations! You’ve successfully set up SSH for GitHub, which means you can now use SSH-based commands to interact with your repositories.
Hi alexcalaca! You've successfully authenticated, but GitHub does not provide shell access.
Output
Top comments (0)