If you’ve ever tried to clone a repository from GitHub and gotten a “Permission denied (publickey)” error, you may need to create an ssh key and share it with GitHub. This post will walk through that process. The commands used in this post are for Mac and Linux.
The first thing you’ll need to do is create an ssh key. To do so, enter
ssh-keygen into your terminal. You will be asked a series of questions about where to save it and to enter a passphrase. The default location is usually fine and you don’t need to enter a passphrase, so you can just hit
return to skip those steps. If it works correctly it will create some nice ASCII art.
Now you’ve created both a public and a private key. The public key is
id_rsa.pub and the private key is
id_rsa (no file extension). You can take a look at your public key by entering
This is the public key that you can share with external entities like GitHub. You can also look at your private key by entering
cat id_rsa, although you shouldn’t need to. That key is just for your system and not for sharing with others or posting on blogs :)
Now you need to go to GitHub and enter your public key. Start by click on your icon on the top right and selecting
Settings in the dropdown.
Account Settings click on
SSH and GPG keys.
Then enter a title and copy everything that printed when you ran
cat id_rsa.pub and paste it into GitHub. This includes the
ssh-rsa at the beginning and the
username@host at the end.
Then all you need to do is click
Add SSH key, enter your password, and you’re all set!