Setting up an SSH Key for GitHub

For detailed instructions, visit this documentation on github.

In this process, you will create two keys:

  • A private key that is stored on your local machine

  • A public key that is stored on Github

This public/private key pair is used to securely transfer data from your local machine to the server hosted by Github. In other words, the keys are used by git to

  • download changes from the remote repository to your local repository (e.g. using pull or clone)

  • upload changes from the local repository to the remote repository (e.g. push)

1. Create a github account (if you don’t have one).

Go to github.com and create an account using your Bryn Mawr email address. Then, send your github username to Professor Shiptoski (kshiptoski@brynmawr.edu).

2. Generate a new SSH key

On your local machine, open a terminal and execute the ssh-keygen command.

$ ssh-keygen -t ed25519 -C "your_email@example.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/alinen/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/alinen/.ssh/id_ed25519
Your public key has been saved in /home/alinen/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:cUr7fXShYj7lz1Rly2TVXQ/tIwg3FPkv/co7BSJBfEA your_email@example.com
The key's randomart image is:
+--[ED25519 256]--+
|         +E+o ..|
|         .o+.  .|
|        o +o+  =+|
|       . =...o*o=|
|        S  + +=++|
|         .o.+o +o|
|          .o..oo.|
|            .o= .|
|              +* |
+----[SHA256]-----+

Notes

  • The -C option indicates a comment. Replace this with your own information.

  • Typing ENTER for the file location will choose the default

  • Typing ENTER for the password will disable a password for this key

3. Add your SSH key to GitHub

Check the contents of ~/.ssh. You should see a private key (name: id_ed25519) and a public key (name: id_ed25519.pub).

$ ls ~/.ssh/
id_ed25519  id_ed25519.pub  known_hosts  known_hosts.old
$ cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBNxuU/ZMS5DfKqdtq6Fd1XPfgMLy/f4KCG0j0+RQ4T0 your_email@example.com

We need to give the public key to Github. Copy the entire contents of id_ed25519.pub and paste it to your GitHub Settings.

  • In the upper-right corner of any page on GitHub, click your profile picture, then click Settings.

  • In the "Access" section of the sidebar, click SSH and GPG keys.

  • Click New SSH key or Add SSH key.

  • In the "Title" field, add a descriptive label for the new key. For example, if you’re using a personal laptop, you might call this key "Personal laptop".

  • Select key type authentication.

  • In the "Key" field, paste your public key.

Click Add SSH key.

4. Test your key

Run the following command.

$ ssh -T git@github.com
Hi alinen! You've successfully authenticated, but GitHub does not provide shell access.

You should see a success message.

Troubleshooting Tips

How to check for an existing SSH key

SSH keys are typically stored in .ssh in your home directory.

ls -al ~/.ssh

What if no agent is running?

If you get an error saying that the SSH agent is not running, use the following command to start it. This command can be placed in your ~/.bashrc file so it runs automatically every time you log into bash.

Start the agent and add your key:

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

5. Try out cloning the lab practice repo.

In your terminal, run the following command:

git clone git@github.com:BrynMawr-CS223-F26/lab1-git-practice.git

Navigate into your new lab1-git-practice folder. Run the following command:

cat README.md

You should see a welcome message. Show your work to Professor Shiptoski before leaving lab.

In the coming days/weeks, we will use git to distribute base code for homeworks and labs, and for you to submit your homework assignments.

Look out for a github invitation from me for your own private repository for submitting your code (named your-github-username-code). This is where you will find your homework instructions and base code each week. You will have to clone your repository like we did above with the lab practice repo. You will then add, commit, and push your code to submit your assignments. Detailed instructions will be included in the first assignment.