Last Updated: February 25, 2016
·
416
· charlie-wasp

Add Public SSH Key to Remote Server in a Single Command

TL;DR

cat ~/.ssh/id_rsa.pub | 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 127.0.0.1). 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 ·