Using SSH keys to login to a server provides a convenient alternative to typing your password each time. SSH key-based authentication also allows scripts to run unattended without leaving your password in plain text. And it does your laundry. Well, alright, maybe not that last one.
Once you have ssh auth setup, you can use commands like
rsync without having to enter a password. Handy!
SSH Keys in 5 Minutes or Less
If you’re lazy or adventurous and prefer to skip the details, you can follow these instructions:
Generate a key if you don’t have one already, pressing enter at all the prompts:
Set permissions on your private key and upload your public key to the server:
$ chmod 400 ~/.ssh/id_rsa*
$ scp ~/.ssh/id_rsa.pub email@example.com:~/id_rsa.pub
Login to the remote server to create the
.ssh folder, create the authorized keys file and set permissions:
$ ssh firstname.lastname@example.org
email@example.com's password: <enter password>
$ mkdir ~/.ssh/
$ cat id_rsa.pub >> ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys
$ rm id_rsa.pub
Now when you login via ssh, it should use your ssh key instead of prompting you for a password.
SSH Keys in Slightly More than 5 Minutes
If you got stuck in the <5 minutes version, would like to know a bit more about what just happened (or what you’re about to do), or want to learn about some advanced use cases, read on.