If you have to manage a lot of servers or run remote scripts in cron, SSH keys are a lifesaver. It’s so nice to be able to ssh to a machine and instantly log in
without typing a password. Of course, one of the more annoying parts of the process can be setting up the SSH keys on the remote host. Typically, the
process goes something like this:
run ssh-keygen locally,
scp the ~/.ssh/id_rsa.pub to the remote server,
then ssh to the remote server and
append that key to your remote ~/.ssh/authorized_keys file.
The above method works, but if you can do the entire thing with a one-liner, why wouldn’t you?
Here’s the SSH one-liner that will copy your local SSH key to the remote host, so you have to type the password only once in the whole process:
$ ssh email@example.com "cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_rsa.pub