How to Add SSH Keys to Your GitHub Account

How to Add SSH Keys to Your GitHub Account

GitHub offers a convenient SSH key feature for accessing your repositories on the command line. Instead of using usernames and passwords every time you push to or pull from your repository, you can use your key. In this article we’ll learn how to add SSH keys to your GitHub account.

Why use an SSH key?

Using an SSH key is a convenient and secure way to access your account. It’s convenient because you don’t need to remember a long password. And you can make your actual password so brutally long and secure that no human or bot could guess it. The SSH key works like an actual key that only you possess.

How to Create an SSH Key

In order to use an SSH key with Git, you must first create the key on your computer. If you already have an SSH key, you can skip these steps. In order to check if you have a key, you can run this command:

 chris@server# ssh-add -l

Follow along with the steps below to create the key and copy its contents. You will need to open your computer’s default terminal application.

  1. Open the terminal app on your computer.
  2. Enter the following command, substituting [email protected] with your email address:
     chris@server# ssh-keygen -t rsa -b 4096 -C "[email protected]"
  3. Press Enter to accept the default file location.
  4. Enter a secure passphrase.
  5. Press Enter.
  6. Enter this command to display the contents of your public key:
     chris@server# cat .ssh/id_rsa.pub
  7. Copy the contents of your key to your clipboard (we will need it later).

It’s important to remember that the SSH key has two parts: a private key and a public key. As the name suggests, the private key is only for private use. Never ever share your private key with anyone (with exceptions made for your system administrator or other trusted people within your organization). This will be important later.

How to Add an SSH Key to your Github Account

Now we have already seen why you might want to use an SSH key. We also demonstrated how to create an SSH key on your computer.

As mentioned above, we have a private key and a public key. In the steps below you’ll learn how to upload your public key to GitHub.

  1. Log into your GitHub account.
  2. Click your avatar and choose Settings
    GitHub Settings

     

     
  3. Select SSH and GPG keys
    SSH and GPG Keys

     

     
  4. Click New SSH key
    New SSH Key

     

     
  5. Enter a title in the field
    Enter Title

     

     
  6. Paste your public key into the Key field
    Paste public key

     

     
  7. Click Add SSH key
    Add SSH key

     

     

Next Steps

Well done! You now know how to add SSH keys to your GitHub account. Make sure to check out some of our other Git articles:

Looking for a dedicated server? We’ve got you covered.

CM
Christopher Maiorana Content Writer II

Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.

More Articles by Christopher

26 thoughts on “How to Add SSH Keys to Your GitHub Account

  1. thanks for this guide! it was really helpful for me, with simple instructions and even graphics to guide me through.

  2. I am on window and try to do the same but instead of providing email address, while generating ssh, I gave my system Name but getting “Permission denied (publicKey) errror.

    1. Hello Tapan – sorry for your issues with the Public key error. If you follow the directions in the article and use an email address are you getting the same error? The error generally occurs because the email address was incorrect. You can find out more specific information in this article regarding that error: https://docs.github.com/en/authentication/troubleshooting-ssh/error-permission-denied-publickey.

  3. It all doesn’t work from when trying to display the contents of your public key using: cat .ssh/id_rsa.pub (you get to a brick wall as the git responds with: “cat: .ssh/id_rsa.pub: No such file or directory”) – Therefore I believe this guide has become out of date and not useful anymore as from May 2022.

    1. Hi Adi, and sorry to hear that you’re having trouble adding your SSH key to your Github account. That type of error message would normally occur if the file is saved to a different location, or with a different filename. Certain OSs will download files to unexpected places or remove the filetype suffix at times, so please make sure the file as listed is in the correct directory and let me know if you’re still encountering the error. Hope that helps!

  4. Can you please help? I tried it but GitHub says You must supply a key in OpenSSH public key format.
    How can I fix this.
    Thank you very much in advance!

    1. Hi Will, sorry that you’re having difficulty setting up Git.

      First, I just wanted to double check that you’re using the public key file — it should end in .pub. If you are, and are still running in to trouble try using this command to generate a key: ssh-keygen -t ed25519 -C "[email protected]"

      Just be sure to replace the example email with the email you intend to use. That should provide you with a workable key file. I hope that helps!

  5. I rarely give comment on web info. This one I am giving a five star. I am new to Git and Mac as well. I have spent hours and hours searching online but did not find a complete answer until I got to this web site. Thanks to the author who composed this page.

    1. Thank you for the kind words, and it’s great to hear that you found the article so helpful. I made sure to tell the author for you!

    1. I’m sorry to see that. We appreciate your feedback so that we can make improvements in our Support Center. Is there a particular step that was not working for you?

      1. The article worked for me on GitHub.

        For those who may have problems, I’d suggest perhaps dropping the -b 4096 switch and adding the -o switch to force an updated OpenSSH format.

        ssh-keygen -o -t rsa -C “[email protected]

        That should create an SSH key that will work on all platforms. You can find an article on creating an SSH Key by Stuart Burns in Techtarget.com (SearchIT operations) for more detail.

Was this article helpful? Join the conversation!