In this article we will show you how to add SSH key to Github to be able to push changes to your remote repositories in Github.
Let’s see how!
Introduction
In order to be able to push our local changes to Github, we will need an SSH key set to provide Github a way to know that we have permissions to push changes into our repositories.
When you don’t have permissions to push changes to a repository, the error you will normally get is the following:
$ git push
ERROR: Permission to theboreddev/myrepository.git denied to theboreddev.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
In this article, we will assume that you already have an existing SSH key on your machine under your ~/.ssh
folder.
If for any reason you still don’t have one and you would like to learn how to generate one, you can check our article “How to Generate SSH Keys”.
Assuming you already have your new SSH key, you will have to add it as a valid SSH key into your Github account. That’s the way that Github will know that you are a “trusted” user for that account when connecting through SSH.
1 – Settings
The first you will have to do is to go to your Github account settings. You will find them in the top-right menu displayed under your account’s icon:

Once you click on settings, you will be redirected to the “Settings
” page, as expected.

In your Settings
page, you will find a section named “SSH and GPG keys
“, click on it to go to the next step.
2 – SSH and GPG keys
You will be redirected to the SSH and GPG keys section. In this section, you will find right at the top of the page a link to create a new SSH key.

Click on this button and we will arrive to our final step!
3 – Add Public Key
In our final step, we will add the public key for our SSH key into this last section. The form prompted to us looks like this:

In the title
field, you can fill what you wish to. This is just a way for you to remember what that public key corresponds to when you have multiple SSH keys set up.
As the public key will only be used once, normally this would include something descriptive enough to be able to identify the machine where the SSH key is located.
The Key
field, on the other hand, must include the public key for your SSH key. To get the public key for your SSH key, you can run the following:
cat ~/.ssh/id_boreddev.pub
This will print the content of your public key, you will have to copy it and paste it in the Key
section in Github.
Alternatively, if you are a Mac user, you can also run this command to automatically copy the output of the command:
cat ~/.ssh/id_boreddev.pub | pbcopy
Once your public key has been pasted into the form, just click on “Add SSH key
” at the bottom.
When you click on that button, it will ask for the password of your Github account.

4 – Confirm Key Has Been Added
Once the key has been added, if you go to “SSH and GPG keys” section in your Settings
again. You should be able to see that there’s an SSH key listed there:

In our case, we called our SSH key mac-m1
and that’s how it appears listed in our settings.
Conclusion
In this article we have learned how to add an SSH key to a Github account. This is a must-know for every developer, as we will be using SSH keys to push changes to our repositories most of the times.
That’s all from us today! We hope you’ve found this article useful and hoping to see you back soon!
Thanks for reading us!
You must log in to post a comment.