GitHub SSH setup is one of the things that you do once every time you get a new computer or gain access to a new server. This tutorial shows how to configure GitHub on your local machine using the command line.
If it is your first time using GitHub on your computer, the first thing you need to do is to download it and tell GitHub which computer you are using to access GitHub data a.k.a upload your SSH key(s) to Git.
1. What is a Github SSH key?
An SSH key is a cryptographic key pair that is used for authentication purposes to securely log in to a server, or in this case, to a Github account. When you use an SSH key to log in to your Github account, you are able to authenticate your session without having to enter your username and password each time you want to access your repositories.
An SSH key consists of two parts: a public key and a private key. The public key is used to encrypt data that is sent to the server, while the private key is used to decrypt the data. When you generate an SSH key pair, you keep the private key on your local machine, and you add the public key to your Github account. When you log in to your Github account, the server uses your public key to encrypt a message, which can only be decrypted using your private key.
This provides a secure and convenient way to log in to your Github account, especially when you need to automate certain processes or when you need to access your repositories from multiple machines. By using an SSH key, you can avoid the security risks associated with storing your password in plain text or using it repeatedly for authentication purposes.
2. GitHub Generate SSH Key
Before starting the GitHub SSH setup, I’m assuming that you already have a git account and it is also installed on your computer (you can check by typing which git)
If this is the case, the next step is to set up your Github account locally:
$ git config --global user.name "YOUR_USER_NAME" $ git config --global user.email "email@example.com"
Next, you should generate an SSH key if you have not yet. You can do it by checking if the files ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub exist.
If not, you can run the following command to generate it:
$ ssh-keygen -t rsa -C "firstname.lastname@example.org"
Now that you have generated the SSH key, it should be copied and uploaded to git. Using the command below, you can copy the key:
$ pbcopy < ~/.ssh/id_rsa.pub
3. Uploading SSH Key Into GitHub
Finally, you should upload the key to git following these steps:
Access your git account settings and follow the steps below:
- Click in “SSH Keys” on the left-hand side
- Click in “Add SSH Key” on the hand side right
- Give it a tittle to the key such as “My personal computer SSH key”
- Paste Copied SSH key
- Click in “Add SSH key”
One last check, back on the computer terminal, when you type:
$ ssh -T email@example.com
You should receive a happy message such as this:
Hi YOUR_USER_NAME! You've successfully authenticated, but Github does not provide shell access.
I hope this tutorial helped and you do not have to deal with configuring Github any time soon 🙂
Here are three of my favorite GitHub Books in case you want to learn more about it.
- Introducing GitHub: A Non-Technical Guide by Peter Bell
- Git Pocket Guide: A Working Introduction by Richard E. Silverman
- GitHub For Dummies by Sarah Guthals