GitHub & SSH Keys

Recently I have needed to use my GitHub username and password whenever I do a push. I can’t remember if it was due to the hardware swapout I recently did with my Mac or some other reason.
|
|
It’s been a bit of a pain so I decided to resolve the issue so that my GitHub account makes use of SSH keys simimlar to how I log onto servers (previous post on that).
Generate SSH Key
If you have already got yourself some SSH Keys you don’t need to do this again you could always reuse what is already setup. However if never been done before first of all create a new SSH key and follow the onscreen instructions;
|
|
Now that the keys are generated you will want to copy the public key to your clipboard so that we can add them to your GitHub account. This can either be using pbcopy to put straight into your clipboard or the traditional way for using cat and cut & paste functions.
|
|
Add to GitHub account
Now that we have the public key we need to log onto out GitHub account and go to settings (top righthand side, click on profile picture) and navigate to the SSH keys section;

Now if you click ‘Add SSH Key’ you can populate your public key and associate a name with it;
.
Testing
Now that you have added your key to your GitHub account we should now test everything is working;
|
|
If you get the successful message you should be good to now do a test push back to you repo and see if you are challenged for a username/password again or if it works using your keys.
If you are still prompted it could be that the repo was originally setup using HTTPS method rather than SSH so you will need to alter your local git configuration. Its a lot easier than it sounds, first of all navigate to the repo in question and copy the SSH destination;

Now from the local machine issue the following to change from using HTTPS to SSH;
|
|
Now when I do a git push I dont need to enter a username/password and my SSH keys are used;
|
|