How to add SSH keys to your GitHub account
Serhii Shramko /
3 min read • --- views
Hello everyone!
Today, we are going to walk through the process of adding SSH keys to a GitHub account.
Before we begin, make sure you have Git installed on your system. If you haven't done this already, head over to the Git website, download the latest version, and install it.
Here is a step-by-step guide:
Step 1: Checking for Existing SSH keys
Before creating new SSH keys, check if you already have any pre-existing keys. Open your Git terminal or command line and type:
$ ls -al ~/.ssh
This command lists all the files in your .ssh directory. If you don't find any, you can proceed to generate a new one.
Your SSH keys might use one of the following algorithms:
- ⛔️ DSA: It’s unsafe and even no longer supported since OpenSSH version 7, you need to upgrade it!
- 🥴 RSA: It depends on key size. If it has 3072 or 4096-bit length, then you’re good. Less than that, you probably want to upgrade it. The 1024-bit length is even considered unsafe.
- 👌 ECDSA: It depends on how well your machine can generate a random number that will be used to create a signature. There’s also a trustworthiness concern on the NIST curves that being used by ECDSA.
- 🥳 Ed25519: It’s the most recommended public-key algorithm available today!
Step 2: Generating a New SSH key
In your terminal, paste the following command:
$ ssh-keygen -t rsa -b 4096 -C "shramko.dev@gmail.com"
Replace shramko.dev@gmail.com
with the email address you used to create your GitHub account. Then, you will be
prompted to "Enter a file in which to save the key," - press Enter to accept the default file location.
Step 3: Adding Your SSH key to the ssh-agent
Make sure the ssh-agent
is running:
$ eval "$(ssh-agent -s)"
Then, add your new SSH key to the ssh-agent:
$ ssh-add ~/.ssh/id_rsa
Note: replace "id_rsa" with the name of your key if you have used a different one.
Step 4: Adding the SSH key to Your GitHub Account
- Go to your GitHub account settings.
- Click on 'SSH and GPG keys' in the menu on the left-hand side.
- Click on 'New SSH Key'.
- Title it appropriately, then copy the SSH public key to the 'Key' input.
To copy the SSH key, go back to your terminal and type:
$ clip < ~/.ssh/id_rsa.pub
Paste the key into the 'Key' input on GitHub, then click 'Add SSH Key'.
Step 5: Testing the Connection
Return to your terminal and type:
$ ssh -T git@github.com
You should see a message welcoming you: "Hi [Your GitHub username]! You've successfully authenticated, but GitHub does not provide shell access."
You've now successfully added an SSH Key to your GitHub account.
Share it: