Add multiples SSH keys on the same host

This is a case if you use the same machine for work/home. You will need to be able to use different keys for different host.

One for

One for

Assuming that you already use id_rsa key for your all we need is tell to ssh-agent to use the other key when the host is

First, create a key for your work key

Creating new key

$ ssh-keygen -t rsa -C "" -f "id_rsa_WORK"
# Your identification has been saved in id_rsa_WORK_rsa.
Your public key has been saved in
The key fingerprint is:
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |

This will generate id_rsa_WORK in your .ssh folder.

Ensure ssh-agent is enabled:

$ eval "$(ssh-agent -s)"
# Agent pid 59566

And we need to tell the agent about our new key

$ ssh-add ~/.ssh/id_rsa_WORK
# Identity added: id_rsa_WORK (id_rsa_WORK)

Configure per host

When you clone/push an git repo from work, you use an uri like , we need to tell the agent that when we use this host to use a different key.

This is done adding into the .ssh/config file

User git
IdentityFile ~/.ssh/id_rsa_OTHERUSER

Setting user

For the last, we need to change the user for the local repo.

So after clone the repository, set your work user

git config "work_username"
git config ""

As we don't user global option, so this configuration will be placed in local repository only.

You can test the new key using `ssh -v`

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.