Home > Help Center > Shared Hosting > Website > SSH Key-Based Authentication with PuTTY

SSH Key-Based Authentication with PuTTY

This tutorial is continuation from our previous article SSH Connection with PuTTY.

In the previous article we used PuTTy to create SSH connection with our hosting using only hosting credentials. We also used PyTTy to automatically submit our cPanel username during the login process.

Start PuTTY, click on the custom session name and click Load button – you must see the correct IP address and Port.

Click on Connection > Data to check if your cPanel username is in the Auto-login username field.

If not – read the previous article first and then come back here.

If yes, let's go ahead.

Download PuTTYgen and Pageant

For this second part you'll need two more tools from PyTTY family – PuTTYgen and Pageant. You can download them from the same URL and if in doubt on which version to download use 32-bit:

ssh key authentication

Start PuTTYgen:

ssh key authentication

Make sure the value in the bottom right corner is no less than 2048 bit and click Generate button. Move your mouse over the blank area according to screen instructions.

ssh key authentication

ssh key authentication

The key is generated and from here we can go in three different directions:

  • To use the key without passphrase – less secure but password less way to login
  • Use passphrase – secure, but you have to enter it with every single login
  • Use passphrase and let Pageant to supply the password – you will only have to enter it once if the Pageant has stopped working.

Let's go through all scenarios.

Use the key without passphrase

Leave Key passphrase and Confirm passphrase fields empty and click Save private key button.

Confirm saving without passphrase:

ssh key authentication

Save the key as private.pkk file (you can choose any name).

Now start PuTTy and login with your hosting credentials.

We are going to create special named directory and file to hold our public key.

Execute all four commands:

mkdir ~/.ssh
chmod 0700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 0644 ~/.ssh/authorized_keys

ssh key authentication

In PuTTYgen select and copy the public key:

ssh key authentication

In the terminal (PuTTy) open authorized_keys file and paste in it the public key (right click in the terminal):

nano .ssh/authorized_keys

and make sure the whole public key code is on one row: ssh key authentication ssh key authentication

Otherwise you are going to get an error:

ssh key authentication

Click CTRL+O then click Enter to save the file.

Click CTRO+X to close it.

Close PuTTy (exit > Enter).

Start PuTTY in a new session and go to Connection > SSH > Auth:

ssh key authentication

Click Browse and navigate to your .ppk (private key file).

Click Session (at the top of the left menu to return to the main screen).

Select session name and click Save:

ssh key authentication

Double click on the session name or select it and click Open:

You are logged in without supplying any password:

ssh key authentication

Use the key with passphrase

If you have closed PuTTYgen start it again, click Load and open the previously saved .ppk file.

Fill in Key passphrase and Confirm passphrase fields and click Save private key button.

ssh key authentication

Confirm overwriting the existing file.

Start PuTTY in a new session, double click on the session name and you'll be prompted to enter passphrase:

ssh key authentication

Let Pageant supply the passphrase

Start Pageant – it works as a background process and can be accessed from the taskbar.

Right click on the icon and select Add Key:

ssh key authentication

Enter the passphrase and click OK:

ssh key authentication

Start PuTTY in a new session, double click on the session name and you are logged in instantly:

ssh key authentication

Looks like the perfect solution.

But let's stop Pageant to see what will happen. Right click on Pageant icon in the taskbar and select Exit:

ssh key authentication

Start PuTTY in a new session – passphrase is needed:

ssh key authentication

Start Pageant, right click on the icon and select View Keys:

ssh key authentication

Click Add Key button:

ssh key authentication

Enter passphrase and click OK:

ssh key authentication

The passphrase is stored until next Pageant stop. Start PuTTy for the last time in this tutorial:

ssh key authentication

Summary

Though the passwordless method looks very tempting – set it and forget it, we recommend you to use the last option with passphrase protected key, delivered by Pageant upon each login.

#ssh #apps

Still not finding what you're looking for?

Contact our support team with any additional questions or concerns.

Contact support