How can we help? 👋

How to configure SSH keys with Putty

This article demonstrates how to generate an SSH key with Putty on Windows and how to configure and use it for your Linux server.

Generating an SSH key with PuTTY on Windows and configuring it on a Linux server involves several steps.

Generating an SSH Key with PuTTY on Windows

  1. Download and Install PuTTY
    1. If you haven't already, download PuTTY from here. It includes PuTTYgen, which is used for generating SSH keys.

  1. Open PuTTYgen
    1. After installing, open PuTTYgen. This is the tool you'll use to generate your SSH key pair.

  1. Generate the Key Pair
    1. Click on the "Generate" button and move your mouse randomly over the blank area to generate randomness for the key.

      Once the key is generated, you will see a public key displayed in the window.

  1. Set a Passphrase (Optional)
    1. Enter a passphrase for added security in the "Key passphrase" and "Confirm passphrase" fields. This passphrase will be required whenever you use the key.

  1. Save the Private Key
    1. Click on “Save private key” and choose a secure location to save your private key (.ppk file). Remember this location as you'll need it to connect to your server.

  1. Copy the Public Key
    1. The public key displayed in the PuTTYgen window should be copied. You will need this to set up the SSH key on your Linux server.

Configuring the SSH Key on the Linux Server

  1. Access Your Server
    1. Log in to your Linux server using your usual method (such as an existing SSH key, or username and password).

  1. Create the SSH Directory and Authorized Keys File (If Needed)
    1. Run mkdir -p ~/.ssh to create the directory if it doesn’t exist.

      Then, touch ~/.ssh/authorized_keys to create the file for storing authorized keys.

  1. Edit the Authorized Keys File
      • Open the file by running nano ~/.ssh/authorized_keys (or use any other text editor).
  1. Add Your Public Key
    1. Paste the public key you copied from PuTTYgen into this file on a new line.

      Save and close the file (in nano, press CTRL + X, then Y, and Enter).

  1. Set Proper Permissions
    1. Run chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys to set the correct permissions.

  1. Restart SSH Service
    1. Depending on your Linux distribution, you might need to restart the SSH service. Use service ssh restart or systemctl restart sshd.

Connecting with PuTTY Using Your SSH Key

  1. Open PuTTY
  1. Enter Host Details
    1. In the “Host Name (or IP address)” field, enter your server's IP address or hostname.

  1. Load Your Private Key
    1. Go to “Connection” > “SSH” > “Auth” in the PuTTY configuration menu.

      Click the “Browse” button and select your private key file (.ppk file) that you saved earlier.

  1. Optional: Save Session for Future Use
    1. Return to the "Session" category, and in the "Saved Sessions" field, give your session a name and click “Save”. This allows you to quickly load these settings in the future.

  1. Connect to Your Server
    1. Click “Open” to initiate the SSH connection.

      If you set a passphrase for your private key, you’ll be prompted to enter it.

  1. Verify and Accept the Host Key (First Connection Only)
    1. The first time you connect, you'll see a security alert about the server's host key. Verify the key, then click “Yes” or “Accept” to continue.

You're now connected to your Linux server using SSH with your PuTTY key! This setup enhances your connection's security by using SSH keys instead of traditional passwords.

Did this answer your question?
😞
😐
🤩