What are SSH Keys? (Easier than what you learned in Computer Security class)
SSH keys are one of the common authentication techniques people use to log into a Unix session (the most common authentication technique is login & password).
If you are like me, you get sick and tired of typing in your login and password every single time you open a new terminal to connect to a Unix session. This is where SSH keys help me everyday by letting me authenticate against the key once, and every new shell session I start will authenticate using the same SSH key.
All you have to do is create a pair of public and private keys. In this analogy, the public key is the house lock and the private key is equivalent to the house key.
Private Key = House key
Public Key = House locks
Using an SSH key to authenticate is like using one key for all the doors in your house instead of having a bunch of combination padlocks (with the same unlock combination) on all your doors.
How to Setup SSH Key Authentication (using OpenSSH)
- Run ssh-keygen and follow prompt (# ssh-keygen -t rsa -b 2048)
- Save the key as id_rsa under your ~/.ssh/ directory
- Create a password for the key pair
- You will get two files:
- id_rsa (this is your private key)
- id_rsa.pub (this is your public key)
- Log into your desired machine (using login & password this time)
- Append the contents of your local id_rsa.pub into the machine’s ~/.ssh/authorized_keys
- Log out
- Log back in and you should notice that you will not need to type the username and password anymore
- Repeat this with any other number of machines you log into often