How to Add SSH Key to GitHub Account

Adding a ssh key to your github will allow you to access repositories via ssh rather then https.

Generating SSH Key Pair

Open a terminal and type –

sudo ssh-keygen -t rsa -b 4096 -C "A comment to identify this key"

Note

-C stands for comment. It’s a common practice to use an email address here but you can put anything to identify this ssh key.


This command should invoke an interactive process for user inputs for the storage and pass-phrase protect your secret key. If the default settings are used, this should create a RSA key pair in the ~/.ssh/ directory.

Adding SSH Key to GitHub

Go to GitHub and loginto your acount. Go to settings. Select SSH and GPG Keys from the left menu.

Click on New SSH Key. Once the new page opens, add a Title for the ssh key. Choose something easy to remember and easy to identify this ssh key.

Now go back to the terminal window and extract the content of the public key. It’s usually saved as id_rsa.pub. Considering the keys are saved in ~/.ssh/

cat ~/.ssh/id_rsa.pub

Copy the content of the public key and go back to GitHub and paste the content under Key and press Add SSK Key.

If GitHub doesn’t show any error then the SSH key has been added successfully. You can see the newly added ssh key listed under SSH and GPG Keys in the settings menu now.

Enjoy!