What are SSH Keys ?
SSH Keys are based on the SSH cryptographic network protocol, which is responsible for the encryption of the information stream between you and the remote machine.
Why should we use SSH Keys ?
SSH keys provide a more secure way of logging into a virtual private server with SSH than using a password alone. While a password can eventually be cracked with a brute force attack, SSH keys are nearly impossible to decipher by brute force alone.
How does the SSH Key Login work ?
The SSH Key is a key pair that provides you with two long string of characters: a public and a private key. The public key is kept on the server that is then unlock it by connecting to it with a client that already has the private key. When the two match up, the system unlocks without the need for a password.
Is this safer than very complex text passwords ?
Hell yeah, see using public key pairs offers considerably more protection than using passwords or password lists which can be captured if the client, the server or the secure session is compromised.
Now that you have an idea of how SSH Keys work and why should we use them lets see how to create and use them.
ssh-keygen -t rsa
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/aodba/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/aodba/.ssh/id_rsa.
Your public key has been saved in /home/aodba/.ssh/id_rsa.pub.
The key fingerprint is:
4a:dd:0a:c6:35:4e:3f:ed:27:38:8c:74:34:4d:93:67
The key's randomart image is:
+--[ RSA 2048]----+
| .oo. |
| . o.E |
| + . o |
| . = = . |
| = S = . |
| o + = + |
| . o + o . |
| . o |
| |
+-----------------+
cat ~/.ssh/id_rsa.pub | ssh user@123.12.12.123 "mkdir -p ~/.ssh cat ~/.ssh/authorized_keys"
ssh user@<remove host
The authenticity of host 'server ip (server ip )' can't be established.
ECDSA key fingerprint is fd:fd:d4:f9:77:fe:73:84:e1:55:00:ad:d6:6d:22:fe.
Are you sure you want to continue connecting (yes/no)? yes