Adding SSH keys on Github

Júlio Xavier
Sep 9, 2018 · 2 min read

"Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network." — Wikipedia.

On Github when you interact with repositories you can choose between two main authentication methods: SSH or HTTPS. Using HTTPS means that you always have to type your user and password when executing an action, like cloning a repository or pushing changes. SSH will make your life easier in this aspect and it's even more secure, that's why I believe you should use it.

“black and gray laptop computer turned on” by Markus Spiske on Unsplash

Note: this example is for Github, but the flux is very similar when setting up SSH authentications on other services, like Digital Ocean.

  1. Open your terminal and go to your ssh folder (if it doesn't exist, create it).
$ cd ~/.ssh/

2. Generate your public/private key pair. The `-C` stands for comment, in this example we will use our mail, but it can be something that helps you remember for what this key is.

$ ssh-keygen -C "your_mail_on_gh@gmail.com"

You will be asked in which file you want to save the key, the default is id_rsa, but let's use an custom file here.

Enter file in which to save the key (/Users/YOUR_USER/.ssh/id_rsa): /Users/YOUR_USER/.ssh/github_rsa

Let's leave it without passphrase for now. Just leave it empty and hit enter twice.

And that's it! Key generated. 🎊

3. Now you should see that we have two new files on our .ssh folder, github_rsa and github_rsa.pub. The first one is your private key, and you should not share it, otherwise you security would be compromised. The second is a public key (.pub) and will be the one used to authenticate. Copy that:

$ pbcopy < github_rsa.pub

4. Finally, go to your keys settings page on Github (Personal Settings > SSH and GPG keys). And click on New SSH key. Give it a title you want and paste your SSH public key on the second box.

After confirmation you should be redirected to your keys settings page with the new key. And you're ready to go!

You can test it cloning a repo and you should not have to type your password anymore.


💻 Let's keep contact! Find me on Github, Twitter and LinkedIn.

Júlio Xavier

Written by

Fullstack JS Developer at Turtle AI. Working with startups from all over the world. In love with coding and self-improvement.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade