Set up SSH on Github

If you want to setup SSH trust between your local development machine & a project hosted on Github, please follow the process below & you will be able to setup it. This process is tested on Fedora/ Ubuntu but it should work on any Linux based OS. On your local Linux machine please generate a RSA SSH Public key if already not generated. You can check it by going to .ssh folder of home directory. If not please execute the below command and follow the instructions:

Step 1:

 ssh-keygen -t rsa 

After you are done with generating SSH key Please execute the below two commands on terminal.

 eval "$(ssh-agent -s)" 
 ssh-add ~/.ssh/id_rsa 

Now copy the content of id_rsa.pub to clipboard.

Step 2:

Open this URL in your browser : https://github.com/settings/ssh  , you will see there are two options are there to be filled.

Title : <Your Title> you can fill some meaningful title here. example : Shashank’s Fedora Laptop Key

Key : Paste the content of id_rsa.pub file & save it.

You can verify it by running below command on terminal.

ssh git@github.com

It will show your github username with some other information. If not please check the steps above.

Step 3:

Now, goto your git project’s home directory and run below command:

git remote -v

Below result should be shown on Terminal.

origin https://github.com/USERNAME/PROJECTNAME.git (fetch)
origin https://github.com/USERNAME/PROJECTNAME.git (push)

Your fetch and push origin URL Will be listed. If it is a HTTPS URL change it by running,

git remote set-url origin git@github.com:USERNAME/PROJECTNAME.git

Verify it by running “git remote -v” again. You will get below result on terminal.

origin git@github.com:USERNAME/PROJECTNAME.git (fetch)
origin git@github.com:USERNAME/PROJECTNAME.git (push)

Now , goto your projects home and try to run git commands to Fetch/ Pull from origin it’ll work through SSH.

If you feel there is a better way to setup SSH on Github please leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s