Setting up ssh keys

Table of contents

The problem

If you are getting authentication issues when trying to clone or update your own private repository, then you will need to add your ssh keys to your GitHub account.

For more detailed information, please see the article here and here, but here’s a quick and dirty guide for setting things up.

Generating your keypair

To generate your public/private keypair, you will need to start from a terminal window on your Linux machine (doing this from Gitbash or Powershell will not work!).

$ ssh-keygen

Accept all the defaults and enter a passphrase if you’d like to use one (you can leave it blank if you’d prefer not to). When the generation completes, two new files will show up under your .ssh/ directory under your home directory.

You can check its contents using:

$ ls ~/.ssh/

You should see two new files, depending on your system, they are id_rsa and id_rsa.pub, or id_ed25519 and id_ed25519.pub.

Finally, copy your public key (i.e., the one that ends with a .pub), you can display it on the screen using:

$ cat ~/.ssh/id_ed25519.pub

(or replace with id_rsa.pub if that is your case). You can simply type cat ~/.id_ and then press the <tab> key and the terminal will autocomplete it for you. Then complete with the .pub suffix.

Add your key to GitHub

Next, open up a browser window and navigate to the GitHub homepage. Open your account settings by clicking on the user icon in the upper-right corner and then choose settings from the drop down menu.

On the settings page, select SSH and GPG Keys from the menu on the left and click the New SSH Key green button.

Give the key a name (e.g., Ubuntu wsl2 key) and then paste the key you copied from above into the large text box. Finally, click the Add SSH Key button.

Notes

Please note that even if you generate and add your keys, you will not be able to write to the class repository. You only have write-access to your own private repository, so make sure to read and follow the instructions for each lab to make sure you are working on the right stuff.


This page was last edited by Mohammad Noureddine on Mon 02 Dec 2024. If you notice any typos or inaccuracies, please open a GitHub issue on this repository.