I have already set up public/private key pairs for ssh login on a server A without password. The problem is that I also want to log on another server B without password. I searched a little online. It looks like many tutorial just applies in the case that there is one server to log in. Following directly that will erase my setting for server A. So how can I add another public/private key pair for my server B, so that I can log in without typing password every time? Thanks!

1 Answer 1


You could just add the public key to the authorized_keys file on server B, then the same key would be used to log into server A or Server B.

Alternately, you can specify the private key to use when authenticating to a server:

ssh -i /path/to/id_rsa user@hostB

Ideally, you'd have a single private key, and add the corresponding public key to all the servers you wished to login to (all using the same private key.)

  • thanks for your reply! I am having problem with understanding both solutions you proposed. For the first one, suppose I am now on linux machine M and want to log on server B without inputing password every time, I copied the line ~/.ssh/id_rsa.pub on machine M (which has only one line ) and appended at the end of the file ~/.ssh/authorized_keys on server B. But still I am asked to input password when login using: ssh [email protected]. This file of ~/.ssh/id_rsa.pub on machine M is generated when I set up the automatic (password-free) ssh login to the server A on machine M.
    – wiswit
    Dec 7, 2015 at 9:23
  • For the alternative solution you suggested, I tried: ssh -i .ssh/id_rsa [email protected] from the machine M, I can use the password to log in successfully. However, when I do "ssh [email protected]", the prompt for password still jumps out.
    – wiswit
    Dec 7, 2015 at 9:29
  • @wiswit - you should take a look at the logs on serverB - typically if it's not allowing login with keys it might be disabled, or (more likey) there might be permission issues with your authorized_keys file that prevents it from being used.
    – chander
    Dec 7, 2015 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .