Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Somewhere I read that to access a remote machine through SSH we need to copy ~/.ssh/ of the local machine to ~/.ssh/authorized_keys of the remote machine. I did this and I can access remote machine through ssh.

I want the remote machine to be accessible from multiple servers, like: Machine A can access machine B, and there is another machine C which can also access machine B.

I copied ~/.ssh/ of machine A to ~/.ssh/authorized_keys of machine B and I can access machine B.

But I also want to access machine B from machine C then what should I do? I mean, where should I copy ~/.ssh/ of machine C to machine B so that I can access machine B from machine C?

share|improve this question
up vote 7 down vote accepted

The authorized_keys file on a remote host can contain more than just one public key. Just append them – make sure that each key gets a new line.

To simplify this process, there is ssh-copy-id(1).

ssh-copy-id user@machine-B

You can execute the above command on Machine C. It will copy the default public key to Machine B and append it to authorized_keys automatically. You can also specify another public key to be copied by using the -i option if you want.

Here's the reference in the manual:

The user creates his/her key pair by running ssh-keygen(1). This stores the private key in […] ~/.ssh/ (protocol 2 RSA) in the user's home directory. The user should then copy the public key to ~/.ssh/authorized_keys in his/her home directory on the remote machine.

The authorized_keys file […] has one key per line, though the lines can be very long. After this, the user can log in without giving the password.

share|improve this answer
thanks for your reply but ssh-copy-id user@machine-B command is not working. Its giving error "ssh-copy-id: command not found". – Amrinder Singh Mar 14 '12 at 5:50
Then you have to install it. It doesn't come with every system. – slhck Mar 14 '12 at 8:03

Alternatively, you can run this command:

cat | ssh remote-user@remote-host "cat >>~/.ssh/authorized_keys"

In order to append to the authorized_keys file

share|improve this answer

You must log in to answer this question.

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