Published

2025-01-24

Create and add an ssh key to GitHub

In order to push commits to GitHub you need to have authentication setup. While there are a couple of ways to do this, we recommend using ssh keys. The steps below will walk you through how to create an ssh key (if you don’t already have one) and add it to your GitHub account.

Before doing step 1, check if you already have a key pair generated. Open a shell and run:

ls ~/.ssh/id_ed25519

If a file path is returned, skip step 1. Otherwise, if you get “No such file or directory”, do step 1.

  1. Go to this help article on GitHub, select which operating system you are using for your terminal (either Mac or Linux), then scroll down to “Generating a new SSH key” and follow the instructions there. Stop when you get to “Adding your SSH key to the ssh-agent”.

  2. The keygen command should have created a public and private key pair in your ~/.ssh directory. This is a hidden directory that contains your ssh keys, configuration settings, and other files related to ssh. Verify that the keys exist by typing:

ls ~/.ssh

You should see at least two files in there, one called id_ed25519 and one called id_ed25519.pub. (You may also have other id_* files in there, if you had created key pairs previously.)

The id_ed25519 file is your private key. Do not share your private key with anyone! It remains on your computer, and only on your computer. The id_ed25519.pub file is your public key. You can share the contents of your public key with other servers you want to log in to.

Note: you need a GitHub account to do the following steps. If you do not have a GitHub account, sign up for one by going to https://github.com and following the onscreen instructions. Once you have an account you can proceed.
  1. Now let’s upload your public key to GitHub so that you can use your ssh keypairs when interacting with GitHub. Follow the instructions here: Adding a new SSH key to your GitHub account.

  2. To test whether you were successful, in your terminal run

ssh -T git@github.com

You may be prompted with something like:

> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
> Are you sure you want to continue connecting (yes/no)?

If so, type yes. You should then get

Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.

where USERNAME is your username.

You’re now ready to use GitHub!


For more information on what ssh keys are and how they work, see the lecture on ssh from our summer workshop (Day 2, session 1).

Back to top