How to add multiple ssh keys for a single user

If you are using mul­ti­ple email addresses for dif­fer­ent ser­vices and each of them require you to enter a dif­fer­ent pub­lic key, then you need to have a pub­lic key gen­er­ated locally for each such email address.

The only catch is, the default one can live in the file called id_rsa.pub whereas the oth­ers have to live in a dif­fer­ent file and your local ssh would need to know where to find this file.

The fol­low­ing steps also help resolve the error — “Fin­ger­print has already been taken” when you are adding an exist­ing ssh key on your website

Lets say you reg­is­tered 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 con­fig­ure SSH to look for your cus­tom file name. Here’s how thats done.
Edit your ~/.ssh/config file and add en entry for your cus­tom file name which is used by gitlab.

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

And now you can eas­ily 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...