February 4, 2019
February 4, 2019
SSH keys are one of the most secure SSH authentication options. It is definitely more secure than the usual SSH password authentication. Therefore, it is highly recommended to use SSH Key authentication method for connections to your servers.
With password authentication, you can connect to your server from any location, you only need to fill in your password. However, if your password gets leaked, it is a major risk as anyone who knows your password will be able to get into the server.
SSH Key authentication only allows connections from clients whose key matches the one on the server. Basically, you generate a key pair (private key and public key). The private key is placed on your local machine and the public key is uploaded to the server. When connecting to the server, a validation of these two keys is made and if the key pair passes the validation you are allowed to connect. Of course, you can upload keys of multiple users so that you or other authorized users would be able to connect to the server from different computers.
As you can see this is a much safer connection method. In this tutorial, we will focus on Windows users who use PuTTY for connections to the server and show how to generate PuTTY SSH Keys. If you want to generate SSH Keys on Linux or Mac, see this tutorial.
Before you begin this guide you’ll need the following:
Most of you have PuTTY installed on your computers already, however, to generate SSH Keys you also will need PuTTYgen.
No installation is required for PuTTYgen, it will run when you execute the file.
And that is it, you have generated your SSH Key pair. The private key will stay on your computer (do not provide it to anyone) while your public key needs to be uploaded to the server you wish to connect to.
In order for the server to recognize your computer when connecting from PuTTY, you need to attach the private key to PuTTY.
Lastly, you need to upload your public key to the server:
mkdir ~/.ssh | touch ~/.ssh/authorized_keys
chmod 0700 ~/.ssh; chmod 0644 ~/.ssh/authorized_keys
:x, hit Enter button. This command will save changes made to the file.
That is it, you can now use SSH keys instead of SSH password authentication to connect to your VPS.
You have learned how to generate PuTTY SSH Keys using PuTTYgen. This will make your connection to the server a lot more secure and convenient as you will not need to fill in the password each time. We recommend using this way of SSH authentication at all times and disable password authentication for good to completely secure your server. To find out how to completely disable SSH Password authentication on your server and use SSH Key authentication instead, follow this tutorial: How to disable SSH Password authentication on VPS.