How to have multiple SSH keys whilst using the 1Password Agent
I have a bit of a niche use case when using my laptop; I want to be able to access repositories GitHub.com via SSH but using different user accounts.
This requires multiple SSH keys to switch between to access different repositories. The “easy” (but less secure) way is to have both sets of private SSH keys on disk and use SSH config to select the correct identity file.
Quote note on examples: they’re based on you using MacOS but might apply to Linux/WSL - however, I haven’t tested it!
The ‘easy’ but insecure way
In your ~/.ssh/config
file.
Host github-as-user1.com
HostName github.com
User git
IdentityFile ~/.ssh/user1
Host github-as-user2.com
HostName github.com
User git
IdentityFile ~/.ssh/user2
Then to test and use in a real repo:
ssh git@github-as-user1.com
git remote add origin git@github-as-user1.com:user1/private-repo.git
You should see the...