-
Notifications
You must be signed in to change notification settings - Fork 27
Authenticating with GitHub in the Command Line
When working with GitHub in the terminal, you will probably run across errors when trying to push your code back up to GitHub due to invalid authentication. Back a couple of years ago this was a lot simpler, but Github changed the rules to make it more secure - which had the effect of making it harder to set up. Below I lay out how to authenticate with GitHub using an SSH key, which is one of the most commonly used ways of authenticating, and is GitHub's preferred authentication method.
This should work on Windows and Unix, but you may need to change the directory in the cat
command if you are on Windows.
# Generate new key
ssh-keygen -t rsa -b 4096 -C "[email protected]"
This will create the key, don't add a passkey unless you're paranoid about security. Next, print out the contents of the public key.
# Print the contents of the public key, change id_rsa if the file has a different name
cat ~/.ssh/id_rsa.pub
Go to your GitHub, then go to settings > SSH and GPG Keys. Alternatively, click this link: https://github.com/settings/keys. Once you are there, click New SSH Key
, title it anything (but preferably using the same name you used when creating the key - which was probably your email), and paste in the contents of the public key in the Key
Field. Make sure Authentication Key is selected. Click Add SSH Key
to submit.
This will allow you to easily pull and push code to GitHub (hopefully) without errors.
A description is coming soon...
Have any ideas or want to contribute? Let us know!