Generate and Configure Git SSH Key on Linux

July 10, 2015 | Last tested: October 2015 | 571 views | Comments

Simply generate an ssh-key and add it's public key to your GitHub account to be able to authorize your computer to remotely login and connect to it.

This has been tested on Ubuntu OS, but should fairly work the same on other Linux Distributions.

 

Notes: If you are using an existing ssh key, proceed to Step 2.

 

Step 1. Generate a new SSH key

Open a terminal and type ssh-keygen -t rsa -b 4096 -C "your_email@email.com".

$ ssh-keygen -t rsa -b 4096 -C "user@email.com"

 

You will be asked where to save the file, just hit enter

 

Enter a hard-to-guess passphrase. Do not forget your passphrase, you will be needing this in your future ssh connections.

 

SSH key has been created.

 

Step 2. Open ssh agent and add your key to it.

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

 

Step 3. Add your SSH key to your github account.

Step 3.1.

Open the file id_rsa.pub. Just leave it open in the meantime, you will copy all of it's contents later.

$ gedit ~/.ssh/id_rsa.pub

 

Step 3.2.

Login on github and click the View profile and more link located at upper right corner of the page.

 

Step 3.3.

Select Settings.

 

Step 3.4.

Click SSH Keys.

 

Step 3.5.

Click Add SSH Key.

 

Step 3.6.

On the Title field, type something that would remind you in the future that you are the one who added such SSH key. Next, is the time to copy all that's inside id_rsa.pub to the field Key. Lastly, click Add key.

It will appear on the list of keys. You can now close id_rsa.pub file, and log out your github account.

 

What's Next? Test the ssh connection.

Enter ssh -T git@github.com on the terminal.

$ ssh -T git@github.com

Your ssh connection was successful when you see a message similar below.

 

Related Tutorials


Must Read