Let's suppose we have 2 server. The server A and server B The server A and B contain the following linux users 'carlos' and 'peter'

The linux user peter has its .ssh folder with id_rsa, id_rsa.pub and known_host files on server A.

After that, I logged in by putty with user carlos and I scaled to root user by sudo su.

So I wish to copy peter's key(s) from peter@A to peter@B using ssh-copy-id being root. Just in case, I don't know the peter's password on both servers.

Is there any way to copy these keys using ssh-copy-id or another linux command?

1 Answer 1


Just copy the file with scp, rsync, or any other program you are familiar with. There is nothing special with those files.

The ssh-copy-id program is a special tool for a special task, it doesn't fit your requirements.

  • 1
    It might be good to add that private keys probably should not be stored on a server if possible... and that any private keys which are copied should have their permissions set to u+rw or 600 for security purposes... and ssh may refuse to use improperly permissioned keys. Commented Sep 20, 2018 at 17:38
  • @RubberStamp I agree. So let's assume that the keys are at least password protected.
    – RalfFriedl
    Commented Sep 20, 2018 at 18:38
  • it's not working by copying. The server B asks peter's password, according to example above. Addtionally I gave permissions for files of .ssh folder Commented Sep 20, 2018 at 19:50
  • You didn't mention that server B asks peter's password, just that you don't know it. But you did mention being root, so in case it's not obvious you should copy the files as root, and also preserve ownership and permission. On a related note, why not let peter copy the files himself?
    – RalfFriedl
    Commented Sep 20, 2018 at 20:29
  • Just in case, it's an example about peter and carlos (similar in my real case). About your question, yes, I can let peter copy files himself. It works if copy is made by ssh-copy-id. I also gave files the ownership and permissions being root but it didn't work. My question goes if I could do it being root but I realize that user (in this case peter) should do himself. Commented Sep 21, 2018 at 21:36

You must log in to answer this question.

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