How to Connect to a Web Server Over SSH with Private/Public Keys Using PuTTY on Windows

How to Connect to Web Server Over SSH with Private/Public Keys Using PuTTY on Windows

Knowing how to connect to your website over SSH authenticating with Public/Private Key pairing is a great skill. Authenticating and working on your website over SSH is more secure since your connection is encrypted.

Also, with SSH you will be able to perform some cool tasks not available to you over a graphical interface. And you will do them much faster.

That’s why some content management systems offer command line interface to their users. Like, for example, WP-CLI for WordPress or Drush for Drupal.

In this tutorial, you will learn how to connect to your web server over SSH with the Public/Private Key pairing using Windows free SSH client PuTTY.

The process is simple. You begin by creating a Public/Private Key pair under your web hosting control panel. You then move to your own Windows box. To install and configure PuTTY.

You finish the job by copying your Public Key from PuTTY into your server’s authorized_key text file. That’s it. You are then ready to connect with Public/Private key pairing over SSH using PuTTY.

Note: this tutorial demonstrates how to create SSH connection with PuTTY to a server hosted by SiteGround. If you host your site somewhere else, this process may not work for you. In such case, please consult your hosting Support documentation or Support staff.

Let’s get started.

Step #1. Create Your Private SSH Key

  • In your CPanel click SSH/Shell Access

SSH/Shell Access in CPanel

  • You will see the Generate new SSH key pair web form. Fill in the First Name, Last Name, Email, Key Password and Password (Again) fields
  • Click Generate

Fill in the form and click Generate

In a few seconds, you will see The key has been successfully added! message.

  • Click Go Back

The key has been successfully added

You will see familiar Generate new SSH key pair page. Your Private Key is displayed at the bottom of the page, in the Manage current keys section.

The keys created and displayed

Good job! You just created your Private SSH Key. You will create your Public SSH key in a few minutes. For now, let’s move from your web server to your computer.

Step #2. Install and Configure PuTTY

  • Download PuTTY from this site and install it on your Windows box.

Once you installed it, you should see PuTTY and its tools displayed in your Windows Start menu.

PuTTY installed and displayed in Windows Start menu

  • Launch the PuTTYgen tool
  • Go back to your hosting CPanel > SSH/Shell Access
  • Click Private Key 

Click on the Private Key link

You will see your SSH Private Key encrypted text displayed in a text box.

  • Copy it into your clipboard

Copy your private key into clipboard

  • Open Windows Notepad
  • Paste the Private Key text into it
  • Save the file as my_private_key.ppk to your Windows Desktop

Save the file as my_private_key.ppk

  • Go back to PuTTYgen
  • Click File > Load private key

Go File > Load private key

PuTTYgen will open the Load private key box.

  1. Select my_private_key.ppk file from your Desktop
  2. Click Open

Select my_private_key file and click Open

You will see the PuTTYgen: Enter Passphrase prompt box.

PuTTYgen: Enter Passphrase prompt box

  • Enter into the box the same passphrase, you entered when you were creating your Private key in your CPanel a few minute ago
  • Click OK

PuTTYgen will display Successfully imported foreign key notice.

PuTTYgen notice about successfully imported key

  • Click OK to close the Notice
  • Click Save private key

Click the Save private key button

You will see the Save private key as: box with my_private_key.ppk file in it.

The "Save private key as:" box

  • Ignore my_private_key.ppk file. Type in my_putty.ppk into the File name: field
  • Click Save

Enter my_putty.ppk and click Save

You will see PuTTY Key Generator interface.

  • Select the Public key text displayed inside the Publc key for pasting into OpenSSH authorized_keys file: box
  • Copy the Public key into your clipboard

Select and copy the public key

  • Go back to your hosting CPanel > SSH/Shell Access
  • In the Upload SSH key section paste the Public key you just copied into the Public Key (DSA or RSA bigger than 2048 bits only): text area
  • Click Upload

Paste in the public key

You will see The key you uploaded has been successfully added to your account! message.

  • Click Go Back

The public key has been successfully uploaded

  • From your Window Start menu launch Pageant

Launch Pageant

  • Click Add Key

Click the Add Key button

You will see familiar Select Private Key File box.

  1. Select my_putty.ppk file
  2. Click Open

Select my_putty.ppk file and click the Open button

You will see the Pageant: Enter passphrase prompt box.

  • Enter the passphrase you entered creating your Private key at the beginning of this process
  • Click OK

Enter your passphrase and click OK

You will now see the key listed inside the Pageant Key List.

The key has been listed

  • Close this Pageant window

Excellent! You are now all set to run an SSH connection to your web server with Public/Private keys using PuTTY.

Step #3. Connect to Your Site over SSH with PuTTY

  • From your Windows Start menu launch PuTTY

Launch PuTTY

You will see PuTTY Configuration window.

  • Click Session
  • Enter <your hosting username>@<your_site_domain> into the Host name (or IP address) field. Make sure in the Connection type: section the SSH radio button is selected

Enter your username@domain

  • Under the Connection tab, click on the + sign next to SSH

Click on the plus sign next to the SSH

  • Click Auth

Click on the Auth

You will see the Options controlling SSH authentication window.

  • Click Browse

Click the Browse button

You will see the Select private key file window.

  1. Select my_putty.ppk file
  2. Click Open

Select my_putty.ppk file and click the Open button

  • Click Open once again

Click the Open button

You will now see the PuTTY command line terminal, resembling the one in the image below.

You will see PuTTY command line terminal

Congratulations! You just connected from your Windows box to your web server over SSH with Public/Private Key pairing using PuTTY SSH client.

Author

  • Alex Smirnov

    Born from Ukrainian mother and Russian father, Alex migrated to the United Kingdom in 1999. He is a self-taught Microsoft Certified Professional. He enjoys learning content management systems and helping web site developers make the most of them.

0 0 votes
Article Rating
Subscribe
Notify of
3 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Steve Brandmaier
Steve Brandmaier
4 years ago

I am new and never realized how complicated it could be to run a website but am thankful for the information.  I have not seen anything like this in any books.

Shane Marchan
Shane Marchan
2 years ago

thank you so much for this.

mikall
2 years ago
Reply to  Shane Marchan

Thanks for commenting!  We are glad you found what you needed here at OST.

3
0
Would love your thoughts, please comment.x
()
x