SSH login using public key
This article will guide you to use PKI encryption to securely login into your VPS
Assumptions: You are using a windows OS PC / laptop and server OS is Linux.
Generate Public key
Download putty-gen executable from https://the.earth.li/~sgtatham/putty/latest/w64/puttygen.exe
After downloading the executable scan it will a good antivirus for your own protection.
Double click the puttygen.exe
Click on the Generate button
After pressing the button move your cursor over space in the area as shown by the red square
The green bar above will show of the key generation
Once the key generation is over you will be seeing the screen as below.
Click on the Save private key button to save the private key you just generated.
You will be prompted for saving the Private key without password confirmation . Click "Yes"
After clicking Yes , it will prompt for location to save the private key . Store it in a safe folder which you will remember .
Similarly repeat the same procedure for Public Key and save it in same location.
You can also copy the Public Key from the below windows.
Add the generated public key to server
Login to the server using putty or other ssh utility and follow the below procedure
cd .ssh
chmod 600 authorized_keys
vi authorized_keys
paste the entire public key as it is into the authorized_keys, save and exit.
chmod 400 authorized_keys
Connecting server using public key
Download putty from https://the.earth.li/~sgtatham/putty/latest/w64/putty.exe
scan it using a good antivirus for your protection.
run putty.exe , you will see the screen of putty as shown below
Enter the IP address and port for your server
The on the left hand side in the Category section go to connections > SSH > Auth
Enter the path /location of the Private Key or browse and select the private key you stored as shown below
After selecting the private key , go to Session to the top in the Category section.
Click on the Open button and you will be prompted for the users name.
Enter "root" or which ever username you have configure (default is root) and press enter .
You will be logged into the server without any password prompt as seen below
Conclusion
Public key authentication is more secure than the password based login method , but you shall always keep the private key in safe location .
Lossing the PrivateKey will lock you out from all servers and you will never be able to recover the keys unless you call up the provider and ask them to help you get into the server using password based login or removing the private key .
So in next article we will se how you can secure the authentication with additional layer of security.
Till then "May The Force Be With You"