How to add multiple ssh keys for a single user

If you are using multiple email addresses for different services and each of them require you to enter a different public key, then you need to have a public key generated locally for each such email address.

The only catch is, the default one can live in the file called id_rsa.pub whereas the others have to live in a different file and your local ssh would need to know where to find this file.

The following steps also help resolve the error – “Fingerprint has already been taken” when you are adding an existing ssh key on your website

Lets say you registered with github.com using exampleOne@gmail.com and with gitlab.com using exampleTwo@gmail.com

# First lets generate our SSH key for github.com
ssh-keygen -t rsa -C "exampleOne@gmail.com"
# Assume you saved the above generated key in the default file id_rsa.pub

# Now lets generate our SSH key for gitlab.com
# We will need to save the next key in a different file.

ssh-keygen -t rsa -C "exampleTwo@gmail.com"
# Assume you saved this one in /home/username/.ssh/id_rsa.two

The next step is to configure SSH to look for your custom file name. Here’s how thats done.
Edit your ~/.ssh/config file and add en entry for your custom file name which is used by gitlab.

Host gitlab.com
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_rsa.two

And now you can easily use each SSH key for each such website.

Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...