Set up GitHub SSH key on Linux

Nwafor Jude
3 min readNov 9, 2020

--

SSH otherwise known as secure shell is a network protocol used to make a secure connection between two computers on an open non secure connection. This enables the connected computers to send an encrypted information.

Lets explain how this works a bit before we go ahead to set up one. Secure shell uses a client server model.

The client stores the private key with the help of ssh agent and the server stores the public key. When the client makes a guess to connect to the server, the server generates an id and sends encoded message to the client. The client decodes the message and send the decoded message to the server. If the decoded message is correct, the server establishes a secure connection with the client and walaaa!!! communication starts.

Now we understand how the handshake works, lets look at how to set up our GitHub ssh key.

  1. Open your terminal with Ctrl + Alt + T

2. Paste the below code in your terminal excluding the dollar sign

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Replace the “your_email@example.com with your own email and press enter.

3. On prompt, enter a file name which you intend to use to store the ssh and press enter.

4. On prompt, enter a passphrase. This might be any sentence at all.

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

We are done creating our ssh key. Next is to add the key to our ssh agent.

  1. start the ssh-agent at the background by pasting the below code to your terminal.
$ eval "$(ssh-agent -s)"
> Agent pid 59566

2. Add your SSH private key to the ssh-agent by pasting the below code to your terminal.

$ ssh-add ~/.ssh/id_rsa

NB: If you have created your key with a different name or you are adding an existing key that has a different name, replace id_rsa in the code above with the name of your private key file.

The final step is to add your public key on your GitHub profile settings board.

  1. If you have no xclip on you machine. Install with the below commands:
$ sudo apt-get install xclip

2. Copy the key to your clipboard with the below code. Ensure that your ssh key file name is correct.

$ xclip -selection clipboard < ~/.ssh/id_rsa.pub

3. Go to your GitHub account settings and click on settings.

4 Click SSH and GPG keys.

5. Click New SSH key or Add SSH key.

6 . Add a title. I normally use the name of the machine for that.

7. Paste your public key into the key field.

8. Click on Add SSH key.

9. On prompt, confirm with your GitHub password and you are good to go.

Congratulations and happy coding if you made it to this point.

About The Author

Jude Nwafor is a software engineer @sterling_bank Plc. You can follow me on twitter @thaddydore

--

--

No responses yet