SSH keys are a very useful tool, as they both make it much easier to login AND make your SSH access much more secure. Plus, they're not that hard to set up!
If you haven't already, you'll need to create an SSH key. To do so, you can use the ssh-keygen
tool like so:
ssh-keygen -t rsa -b 4096 -C "myuser@myhost"
ssh-keygen
- the command/binary we want to run.-t rsa
- the encryption algorithm type to use.-b 4096
- the number of bits to use for key generation (higher = more secure, but slower).-C "myuser@myhost"
- comment for the SSH key. This can be whatever you want, though typically I use something like “user@host” to denote for who and where the key is for.
Copying the key also extremely easy, and again it's thanks to another tool in the SSH toolchain. ssh-copy-id
does exactly what you think it would: copy a key! It's used much like the ssh
command:
ssh-copy-id user@host
ssh-copy-id
- the command/binary we want to run.user@host
- the username and hostname of the system we want to copy the SSH key to.That's all that you need to do! Now you just need to test the setup. Simply SSH in as the user and host that you copied the key to, and see if you get prompted for a password or not.