How to setup SSH Connections to your GitHub repositories

Note: You must have an existing GitHub account

1. Open terminal then run command to generate a new SSH key

$ ssh-keygen

You should see something like this:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/user-name/.ssh/id_rsa): <Just press enter>

Enter passphrase (empty for no passphrase): <Just press enter>
Enter same passphrase again: <Just press enter>

Your identification has been saved in /home/user-name/.ssh/id_rsa.
Your public key has been saved in /home/user-name/.ssh/id_rsa.pub.
The key fingerprint is:
45:63:d5:99:0e:99:73:50:5e:d4:b3:2d:86:4a:2c:14 user-name@client-name
The key's randomart image is:
+--[ RSA 2048]----+
|        E.+.o*.++|
|        .o .=.=o.|
|       . ..  *. +|
|        ..o . +..|
|        So . . . |
|          .      |
|                 |
|                 |
|                 |
+-----------------+

This generates:

  • The id_rsa file, which is the private key file.
  • The id_rsa.pub file, which is the public key file.

2. Copy the SSH key to your clipboard

Using xclip:

$ sudo apt-get install xclip

Downloads and installs xclip. If you don’t have apt-get, you might need to use another installer (like yum)

$ xclip -sel clip < ~/.ssh/id_rsa.pub

Copies the contents of the id_rsa.pub file to your clipboard

Manual copy

Go to your ssh folder directory

 $ cd ~/.ssh

Copy contents of id_rsa.pub file

ssh-rsa EXAMPLE-AfICCQD6m7oRw0uXOjANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMCVVMxCzAJB
gNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDASBgNVBAsTC0lBTSBDb2
5zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAdBgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jb20wHhc
NMTEwNDI1MjA0NTIxWhcNMTIwNDI0MjA0NTIxWjCBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAw
DgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDAS=EXAMPLE user-name@ip-192-0-2-137

3. Sign in to GitHub at https://github.com/

4. In the upper-right corner of the page, click your profile photo, then click Settings

5. In the user settings sidebar, click SSH and GPG keys.

6. Click New SSH key or Add SSH key.

7. In the “Title” field, add a descriptive label for the new key. For example, if you’re using a personal Mac, you might call this key “Personal MacBook Air”.

8. Paste your key into the “Key” field. (This is the contents of your id_rsa.pub file)

9. Click Add SSH key.

10. If prompted, confirm your GitHub password.