3 steps:
- Create multi ssh key
- Add config key
- Change host to using the right key
ssh-keygen -t rsa -f ~/.ssh/key1 -C “account1@gmail.com"
ssh-keygen -t rsa -f ~/.ssh/key2 -C "account2@gmail.com"
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 git@gitlab.com:account1/rider.git
—> git clone git@home.projects:account1/rider.git
git clone git@bitbucket.org:account2/rider.git
—> git clone git@work.projects:account2/rider.git