There’s a good tool for copying ssh keys to remote host under your account: ssh-copy-id. This lets you copy your public key under your account on the remote server.
But what about other accounts? Let’s say you want to log in as root (with key-only auth method, of course)? How to copy key to root user’s .ssh/authorised_keys? One way to do it is to log as your ordinary user, make yourself root with sudo su -, open authorized_keys with editor, paste, save etc… Tedious? Yes.
That’s why there’s a good oneliner:
cat ~/.ssh/id_rsa.pub | ssh your_user@remote.server.com “sudo tee -a /root/.ssh/authorized_keys”
Follow me:
![Follow us on Facebook Facebook](https://measure9.varkel.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/64x64/facebook.png)
![Follow me on Twitter twitter](https://measure9.varkel.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/64x64/twitter.png)
![feather](https://measure9.varkel.net/wp-content/plugins/social-media-feather/synved-social/image/icon.png)
Share me:
![Share on Facebook Facebook](https://measure9.varkel.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/64x64/facebook.png)
![Share on Twitter twitter](https://measure9.varkel.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/64x64/twitter.png)
![Share on Reddit reddit](https://measure9.varkel.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/64x64/reddit.png)
![Share by email mail](https://measure9.varkel.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/64x64/mail.png)
![feather](https://measure9.varkel.net/wp-content/plugins/social-media-feather/synved-social/image/icon.png)