Adding SSH key to GitHub


3 min read

Using the Github SSH protocol, you can connect to GitHub and sync with repositories without supplying your username and personal access token each time you push, pull, merge, or any Github-related command.

You can watch the video tutorial or read the text below.

Generate SSH Keys for GitHub

If you are a windows user or you face any difficulty while generating your ssh keys, you can follow this tutorial and come back to proceed further steps.

First, open your terminal and run

ssh-keygen -t rsa -b 4096 -C ""

Replace "" with your email

It will ask you a few questions, keep on pressing enter till you get the output something like below.

Generating public/private rsa key pair.
Enter file in which to save the key (/home/nitin/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in id_rsa
Your public key has been saved in
The key fingerprint is:
The key's randomart image is:
+---[RSA 4096]----+
| ..o. .+.  .     |
| .=  +o = . .    |
|  .++. . +.. .   |
| ..+.o . o  o .  |
|o...+ . D =.   F |
|+.oo .   * o     |
|==+ .     =      |
|A= .       .     |
|*=+              |

Now run the below command to print the key on the screen.

cat ~/.ssh/

Now copy the output generated.

ssh-rsa AA21adasdasd+VvPxRRYZ7EI354FsLXrsPX97K0XhstPhL3IOKhKUUmD0XuIw7CgNyJuQB7DN1keAM4JPgcfhlzA78RuVJAuUm4MqKrjworsDt4h1olj14FiEu0qpasdasdsadsadwrLGfLEeasdsadasdasdasdT6rqkvnjiIS4iugpbXRK/ykdmNKvBr3ijKmELIuoz5pH32ghDiPwX9u65R0Ss8CYqnODzuE7UxjryNDjyYhCo10TPhFaIwNPu8EP5FzaHBUiN6dm6D7mtORrGtZ8Hhtr5s9rxcuTIc0m1H9rZE799/nyI46Te72CPmNJFnaDT+asdasdasd4aX+CbJEEkQ==

Adding SSH Keys to Github

Github SSH keys are added inside the SSH and GPG keys settings

Follow the steps below to open SSH and GPG keys settings

To add the key, click on New SSH key button at the top right, it will open up a form to fill the key.

  • In this Title field, enter any name to differentiate your key from the keys you will enter in the future

  • In Key field paste the key you copied earlier.

  • Finally, click on Add SSH Key button

Setting Up Git Repository for using with SSH Protocol

If you are cloning a new repository then select the ssh tab while cloning

If you already have the repository cloned then follow the steps below:

  • Open your terminal, change your directory to the cloned repository, and use the below command.

  • git remote set-url origin<github username>/<repository name>

  • Don't forget to change gitusername, repositoryname to yours, like I have set mine below

  • git remote set-url origin

Now ssh keys are set up, you can try pushing them to your Github repository, you will not be asked for a username and password.

I hope, by now you should be able to add ssh keys to your Github account.

You can follow this tutorial to learn basics of Github.

Did you find this article valuable?

Support Nitin Raturi by becoming a sponsor. Any amount is appreciated!