By the end of this chapter, you should be able to:
When you push or pull code from GitHub, it's essential that GitHub can successfully authenticate you before letting you run these commands. This means that every time you try to
git push or
git pull, GitHub will ask you for your email and password, and if they are correct the command will execute. Without authentication, GitHub would be chaos: anyone could push whatever code they wanted to any repository at any time!
So, being able to authenticate people when they push or pull is critical. But it also gets tedious pretty quickly. When you are pushing and pulling frequently, typing your credentials each time is bit of a hassle. Thankfully, if you use the SSH protocol and configure everything properly, you will be able to authenticate without having to put your username and password each time. To do this we need to create an SSH key locally, add it to GitHub, and make sure we can authenticate successfully.
This can be a bit intimidating, but if you follow the steps carefully, you should be able to get this to work. (If you get stuck, GitHub also provides instructions on configuring SSH.)
ssh-keygen -t rsa -b 4096 -C "PUT YOUR EMAIL HERE"and replace "PUT YOUR EMAIL HERE" with the email you used to sign up with GitHub.
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]press enter.
eval "$(ssh-agent -s)". If you do not see a
pidnumber, start from the first step again.
ssh-add ~/.ssh/id_rsa. if you see an error message, start from the first step again.
pbcopy < ~/.ssh/id_rsa.pub.
pbcopydid the copying for you).
ssh -T [email protected]and if you see "Successfully authenticated" (ignore the rest of the message) you are good to go! If you do not see that, start from the beginning again.
This might seem like a pain, but thankfully you only need to do it once. Once the connection is established, you'll be able to push and pull without having to authenticate every single time.
When you're ready, move on to GitHub Workflow