SSH with key based authentication allows you to log on different servers via the personal private key on all servers, needing not to remember several passwords.
SSH key pairs are two secure keys that can be used to authenticate a client to an SSH server. Each key pair consists of a public key and a private key.
Step 1 Generating RSA / DSA Key Pairs
To generate an RSA key pair for version 2 of the SSH protocol:
1 2 3 |
$ ssh-keygen -t rsa |
To generate an DSA key pair for version 2 of the SSH protocol:
1 2 3 |
$ ssh-keygen -t dsa |
it will generate key pairs under ~/.ssh/. The private key is in id_rsa, and id_rsa.pub has a public key
Step 2 Change the permissions of the ~/.ssh/ directory
1 2 3 |
chmod 700 ~/.ssh |
Step 3 add/update authorized_keys
Copy the content of ~/.ssh/id_rsa.pub into the ~/.ssh/authorized_keys on the server you want to connect.
Step 4 Change the permissions of the ~/.ssh/authorized_keys
1 2 3 |
$ chmod 600 ~/.ssh/authorized_keys |