ToolingMar 2026 ยท 1 min read

Two GitHub identities on one machine, without breaking ~/.ssh/config

Work laptop, two GitHub accounts: the company org and my personal one. For a while I hand-edited ~/.ssh/config and prayed. Then I'd push to the wrong remote with the wrong key and spend ten minutes confused. So I fixed it properly โ€” and eventually wrote a CLI so I'd never do it by hand again.

The core idea: host aliases

SSH lets you invent hostnames that map to real ones with a specific key. That's the whole mechanism:

# ~/.ssh/config
Host github-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_work
    IdentitiesOnly yes
 
Host github-personal
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_personal
    IdentitiesOnly yes

IdentitiesOnly yes matters โ€” without it, SSH offers every key it has and GitHub picks the first that authenticates, which may be the wrong account.

Point each repo at the right alias

# work repo
git remote set-url origin git@github-work:acme/service.git
 
# personal repo
git remote set-url origin git@github-personal:ajf1016/sshelf.git

Now the alias in the URL decides the identity. No more guessing.

Why I built sshelf

The config above is fine for two identities. It stops being fine when you've got bastion hosts, imported .pem keys, and a dozen servers. sshelf is a Go CLI that manages all of that behind one interface โ€” profiles, keys, connections โ€” so I stop hand-editing config files and re-learning this every six months.

The tool is just this post, automated.

โ† All writingGet in touch