Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 3

Using multiple accounts on macOS

Solved! Go to Solution.

Hi there! 

 

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!

2 Replies
Community Manager
Message 2 of 3

Re: Using multiple accounts on macOS

Hi @Abd-Ur-Rehman,

 

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:

~/.ssh/config

 

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 (`git@github.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 (`git@work.github.com: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!

Solution
Copilot Lvl 2
Message 3 of 3

Re: Using multiple accounts on macOS

Thanks for your reply. I already have found a solution from here