Last Updated: February 25, 2016
· charlie-wasp

Add Public SSH Key to Remote Server in a Single Command


cat ~/.ssh/ | ssh user@hostname 'cat >> .ssh/authorized_keys'

I often need to add my public (don't confuse with private) key to the remote server, on which I'm gonna deploy my app using Capistrano.

One day I got tired of manually go via SSH to server, open authorized_keys file, and paste my key there. So I've found this little snippet that allows you to make all stuff from above without actually leaving your localhost (there is no place like I've found it here.

All you need is your key (of course) and login-password for one-time access to remote server via SSH

2 Responses
Add your response

There is also the 'ssh-copy-id' command. This will also automatically create the .ssh directory and set the permissions on authorized_keys file properly.

over 1 year ago ·

Thank you, solarnz, didn't know about that!

over 1 year ago ·