I'm having trouble with the SSH keys while using multiple accounts on macOS the key I add 1st into SSH agent only works, the 2nd one doesn't work. Thoughts? How can them both working at the same time or how to setup the accounts?
Thanks in advance!
Solved! Solved! Go to Solution.
Thank you for being here! Working with multiple accounts and multiple ssh keys can be a tricky thing to set up.
Most of the time we recommend against having multiple accounts specifically for this reason, and usually just recommend that users use a single account for both work and personal projects. Still, we know this isn't a good solution for everyone, so hopefully, we can point you in the right direction for setting this up!
To do this you'll need to create an ssh config file in:
The contents should be similar to this, defining two different SSH hosts that point to GitHub but use different keys. You'll need to modify the contents to point to your two separate SSH keys in the `IdentityFile` section:
Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_personal Host work.github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_work
This config sets it up so that every time you clone a repository using a standard SSH URL (`email@example.com:username/repo.git`) it will use your personal account key, but if you modify the URL slightly you can tell it to use your work key instead (`firstname.lastname@example.org:username/repo.git`).
I hope this helps!
Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!