Thank you but I think I have not conveyed the problem correctly. Let me describe the problem again. Let us assume the key is called "ssh-rsa AAAAB3Nxyz user@laptop". Now these are the current configurations:

On my laptop ~/.ssh/id_rsa.pub contains -
ssh-rsa AAAAB3Nxyz user@laptop
On Server B ~/.ssh/id_rsa.pub contains -
ssh-rsa AAAAB3Nxyz user@laptop
On Server A ~/.ssh/authorized_keys contains -
ssh-rsa AAAAB3Nxyz user@laptop

Now when I ssh from my laptop (into Server A) there is no password prompt. But when I ssh from Server B (into Server A) I get the following -
Enter passphrase for key '~/.ssh/id_rsa':

When I enter the password I am able to login. But I do not want the password prompt on Server B. I do not understand why there is this difference in behavior. Why Server B is not able to access Server A without a password prompt while, with the same key my laptop is able to access Server A without a password prompt. I have checked all the permissions, they are fine. Hope this is clear. Thank you.

  • It seems like you've messed things up a bit. 1) Use ssh-keygen -t rsa 4096. 2) Copy the contents of /root/.ssh/id_rsa.pub key e.g from server A to /root/.ssh/authorized_keys on server B and vice versa. Also, there is ssh-copy-id and might be useful in your case. Commented Mar 9, 2018 at 16:40
  • Thank you, but I have edited the question to convey the problem better. I don't think I was clear last time. Could you read it again and see if you can help? Commented Mar 10, 2018 at 16:14

1 Answer 1


You never need to copy the entire ~/.ssh directory, just the contents of the public part of your key(s). Easiest to do assuming password authentication is enabled would be

user@darkstar ~ $ ssh-copy-id remoteusername@remotehostname

And let ssh worry about getting everything in the right spot.

If you need to do it manually, or if you don't have password auth and you must have the sysadmin put the key in place, etc then you need to copy your ~/.ssh/id_rsa.pub file. Once that is on the remote machine, simply add the content to whatever is already in the ~/.ssh/authorized_keys file under the appropriate user account. A simple cat id_rsa.pub >> ~/.ssh/authorized_keys will work.

Finally, you want to ensure the permissions on the private key, the authorized_keys file, and the ~/.ssh directories on both machines are set appropriately - the ~/.ssh directory should be set to 0700 and the files inside of it should be 600.

To fix your issue, log in to the remote machine, rename the existing ~/.ssh directory to something else, re-create it and set permissions properly, log out, and use the ssh-copy-id from above. At that point, you should be able to ssh using your key and whatever passphrase is associated with it.

Edit for updated question You are missing the key pair concept I think. Think about house door locks - in order for one key to open them all, they have to have the same pin combo on the inside.

The id_rsa.pub file for any given combo goes into the authorized_keys file on the remote machine. In order for that key to work, you must have the corresponding private key on the machine you are connecting from. You can deal with multiple keys by having them in different files and using the -i option for ssh (et al) to specify which private key to connect to.

So, using your information you need to get the private key file from the laptop (probably ~/.ssh/id_rsa) and put it on Server B, call it something like ~/.ssh/laptop_id_rsa). When you ssh from Server B to Server A you can do with ssh -i ~/.ssh/laptop_id_rsa user@serverA. If you want to ssh from A to B, repeat the process putting the private key on A. Alternatively you can use server B as a jump host/tunnel so once you connect there with the correct options you can then from your laptop ssh directly to Server A. This keeps your private key file only on your laptop (good thing for security, you don't want copies floating around, especially with a passwordless key!)

You'll also likely want to set up a ~/.ssh/config file so you can simply do ssh serverA and have it use the appropriate hostname, port, username, identity file, etc.

  • Thank you, but I have edited the question to convey the problem better. I don't think I was clear last time. Could you read it again and see if you can help? Commented Mar 10, 2018 at 16:14
  • @DuraiArasan updated!
    – ivanivan
    Commented Mar 10, 2018 at 16:57

You must log in to answer this question.

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