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.
Assuming that you already use
id_rsa key for your github.com 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 "email@example.com" -f "id_rsa_WORK"
# Your identification has been saved in id_rsa_WORK_rsa.
Your public key has been saved in id_rsa_WORK_rsa.pub.
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
firstname.lastname@example.org/project.git , we need to tell the agent that when we use this host
mywork.com to use a different key.
This is done adding into the
For the last, we need to change the user for the local repo.
So after clone the repository, set your work user
git config user.name "work_username"
git config user.email "email@example.com"
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 firstname.lastname@example.org`