- Create a new .ssh directory (if it doesn't exist) in your home directory, cd in and generate new ssh key:
$ ssh-keygen -t rsa -C "email@address.com"
- Print and copy the contents of the public key you just made:
$ cat ~/.ssh/NEW_KEY_NAME.pub | pbcopy
-
Head over to Github > Settings > SSH and GPG Keys > New SSH Key and paste in what you just copied in the Key section. Title should be the the NEW_KEY_NAME exactly as you generated it.
-
Add this key to your identities list (-K adds to keychain):
$ ssh-add --apple-use-keychain ~/.ssh/NEW_KEY_NAME
- Create new config file (if it doesn't already exist) and edit using vi/nano/etc.:
$ vi ~/.ssh/config
- Now add an entry for your new key:
#github
Host github-USERNAME
HostName github.com
User git
IdentityFile ~/.ssh/NEW_KEY_NAME
UseKeychain yes
AddKeysToAgent yes
- While you're in there, you can also "forward" this key to your server upon connecting, which lets you push/pull/clone etc. In that case, tack this on to config as well:
#server
Host DOMAIN.COM
ForwardAgent yes
To test that your key is working on your own machine (or your server should you decide to forward the key), run:
$ ssh -T git@github.com
If all goes well, you'll see (on both client/server):
Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
Protip: you can continue steps 1-6 for multiple profiles (make sure git config is set up appropriately first).