SSH Access to Git

Committing code in Github becomes pain because of it’s asking username and password nature for each and every commit to the repository, specially when you are doing frequent commits.

Github provides a remedy to overcome it through SSH Keys. We can simply create SSH Keys and ask Github to identify our computer and don’t ask for username and password for every commit. It can be easliy done in few steps:

Step 1: Open Git Bash and execute command:


ls ~/.ssh

Step 2: Next, execute below command, and keep on pressing press Enter, it will create default public SSH key.

ssh-keygen -t rsa -C "your_email@example.com"
For example : ssh-keygen -t rsa -C "aggarwalarpit.89@gmail.com"

Step 3: Turn on ssh-agent entering below command:

ssh-agent -s

Step 4: Add generated SSH key to the ssh-agent:

ssh-add ~/.ssh/id_rsa

Step 5: Go to directory /Users/you/.ssh and open the “id_rsa.pub” in notepad and copy the content. Now login to your Github account, click on Settings and from right panel click on SSH Keys. Now, click on Add SSH Key button and paste the “id_rsa.pub” content in it and give it any name you want.

Step 6: Testing the connection, execute below command:

ssh -T git@github.com

Thats all!

Now commit the code in Github using SSH or HTTPS and I am sure Github will not ask you to enter username and password.

Advertisements