Download Putty
If you don't already have Putty and PuttyGen installed, download them now.
Generate Our Keys
We will be generating a public and private key. The public key will be on the server and the private key will remain on your desktop.
First, open up PuttyGen to generate your public and private keys. Click the Generate button and move the mouse over the blank area to generate the keys.
Once the keys have been generated, save both the public and private key. You will also need to copy all of the text from the field labelled "Public key for pasting into OpenSSH authorized_keys file", at the very top of the PuttyGen window.
Configure the Server to use SSH Keys
Open the authorized_keys file and paste the public key that you just copied into it.
nano ~/.ssh/authorized_keys
If you don't already have a ~/.ssh directory, create one before pasting the key.
mkdir ~/.ssh
Set file permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Set the SELinux contexts
restorecon -Rv ~/.ssh
Configure OpenSSH to no Longer Accept Passwords
Open up the sshd_config file using your favourite text editor and turn password authentication off.
nano /etc/ssh/sshd_config
PasswordAuthentication no
Restart OpenSSH
service sshd restart
Connect to your Server Using SSH Keys
Open up Putty on your Windows desktop.
Expand the SSH tree, under the category menu on the left hand side, then click Auth (Connection->SSH->Auth). Now click on the Browse button to your right and navigate to the private SSH key that we generated earlier.
Click on Session at the very top of the category menu, and enter the IP and SSH port of your server. Enter the user that you'd like to connect as and that's it.
Remember to make sure to keep private key secure so as to avoid having your server being compromised.
- Updated