-
Notifications
You must be signed in to change notification settings - Fork 23
Configuring SSH Access to Github
-
Create a new keypair in
~/.ssh/configfollowing these instructions -
Add this to your
~/.ssh/config
Host github.com
IdentityFile ~/.ssh/my_file.key
If you're like me, you have different work and play accounts with github. Note, these instructions are intended for use in MacOS. If you use Linux or Windows, it will be similar, but different.
Start by checking out the repo. You will probably need to use HTTPS and username/password auth for this part:
git clone https://github.com/hackalog/repo-name.git
Now change the upstream origin to use SSH authentication:
cd repo-name/
git remote set-url origin [email protected]:hackalog/repo-name.git
Set the local credentials to match the username you wish to use, and also set the correct SSH key file (the one you created above)
git config user.name "Your Name"
git config user.email "[email protected]"
git config core.sshCommand "ssh -i /Users/$USER/.ssh/id_rsa.github"
Add the credentials to the MacOS key store:
ssh-add -K /Users/$USER/.ssh/id_rsa.github
Test that SSH how identifies the correct user account (without a password)
ssh -i /Users/$USER/.ssh/id_rsa.github [email protected]
And finally, check that it all works:
git fetch origin
If you can't convince MacOS to use the right identity, your old identity is probably still cached. Take some advice from Aliens and do a:
ssh-add -D
ssh-add -K /Users/$USER/.ssh/id_rsa.github