Adding SSH keys on Github
"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.
Note: this example is for Github, but the flux is very similar when setting up SSH authentications on other services, like Digital Ocean.
- 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_rsaLet'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.pub4. 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.
