3 steps:
- Create multi ssh key
- Add config key
- Change host to using the right key
ssh-keygen -t rsa -f ~/.ssh/key1 -C “[email protected]"
ssh-keygen -t rsa -f ~/.ssh/key2 -C "[email protected]"
Add the public key to each account.
Host home.projects
User git
Hostname gitlab.com
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/key1
Host work.projects
User git
Hostname bitbucket.org
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/key2
ssh://git@hostname:<user_name>/<repo_name>.git
Ex:
git clone [email protected]:account1/rider.git
—> git clone [email protected]:account1/rider.git
git clone [email protected]:account2/rider.git
—> git clone [email protected]:account2/rider.git