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.
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 yesIdentitiesOnly yes matters โ without it, SSH offers every key it has and GitHub picks the first that authenticates, which may be the wrong account.
# 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.gitNow the alias in the URL decides the identity. No more guessing.
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.