SSH Help
SSH Help
References:
- The Ultimate Guide to SSH
- How to Set Up Multiple SSH Keys
- Best way to use multiple SSH private keys on one client
Configure More Than One SSH Key
If you need to connect to the same host with different keys, you can achieve it by following these steps.
Example: We want to use one SSH key for work and another for personal use.
Steps
-
Generate both SSH keys:
ssh-keygen -t rsa # use one default path ( ~/.ssh ) ssh-keygen -t rsa # give one different path from default (eg: ~/.ssh2 ) -
Add alias host name:
In your
~/.ssh/configfile, add a similar configuration:Host work HostName bitbucket.org IdentityFile ~/.ssh/id_rsa ## /User/admin/.ssh/id_rsa User git Host personal HostName bitbucket.org IdentityFile ~/.ssh2/id_rsa ## /User/admin/.ssh2/id_rsa User git -
Add SSH private keys to ssh-agent:
The default one will be added automatically.
ssh-add ~/.ssh2/id_rsa -
Use aliases while adding origin (or while cloning):
Then instead of cloning your repos like this:
git clone git@bitbucket.org:username/my-work-project.git git clone git@bitbucket.org:username/my-personal-project.gitYou must do this:
git clone git@work:username/my-work-project.git git clone git@personal:username/my-personal-project.git