Using SSH for Separate GitHub Accounts

I keep my emacs configuration in my personal GitHub account, but choose to use a separate account for my full time job. It's tricky when you want to use SSH for both, but it's definitely doable. Here's my quick notes on how to manage it.

Create a file: ~/.ssh/config

With something like this in it:

Host github-personal
     Hostname github.com
     IdentityFile ~/.ssh/github-personal
     User johncoder

Host github.com
     Hostname github.com
     IdentityFile ~/.ssh/github-fulltimejob
     User my-fulltimejob-github-user

As long as I've set up the separate SSH keys via ssh-add ~/.ssh/<key> then things will work just fine. The only trick is that I need to clone using the Host name:

git clone git@github-personal:johncoder/my-repo

I chose to use github.com for my work stuff, since it could get pretty confusing if I used a different host. My personal stuff isn't something I need frequently on my work machine.

Show Comments