0

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!

2

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 user@serverB.address.fr. 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 '15 at 9:23
  • For the alternative solution you suggested, I tried: ssh -i .ssh/id_rsa user@serverB.address.fr from the machine M, I can use the password to log in successfully. However, when I do "ssh user@serverB.address.fr", the prompt for password still jumps out. – wiswit Dec 7 '15 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 '15 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.