Multiple ssh keys for logging to different sites

It is secure and easy to login into servers with openssh using public/private key client authentication. You only need to generate keys with ssh-keygen and these keys are used automatically.

Challenge starts when you dont want to use same key everywhere but prefer or have to use different keys for different sites.

Firstly lets create a few keys. Add also meaningful comments immediately that help you to remember which key was for what. ssh-keygen offers you choice what you want to have key names

$ ssh-keygen -C "my work key"
$ ssh-keygen -C "personal stuff"

Now copy public key to remote into ~/.ssh/server authenticated_keys or ~/.ssh/authenticated_keys2 file.

Change ssh configuration. Either systemwide in /etc/ssh/ssh_config account basis in ~/.ssh/config. Write into this file where your private keys are and which hosts they apply to.

Host server.atwork.com
  IdentityFile ~/.ssh/id_rsa.work
Host personal.webserver.com
  IdentityFile ~/.ssh/id_rsa.personal

See also Setting up public key authentication

 

 


Leave a Reply

Your email address will not be published.


*