Setting up SSH Keys on Windows using PuttyGen

3 min read 11 hours ago
Published on Jan 09, 2025 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through the process of setting up SSH keys on Windows using PuttyGen. This method allows you to connect to your Linux server without needing to enter a password each time, enhancing security and convenience.

Step 1: Download Putty and PuttyGen

Before you can create SSH keys, you need to download the necessary software.

  1. Visit the Putty download page: Putty Download Website.
  2. Choose the appropriate installer for your system:
  3. Download PuttyGen:

Tip: Ensure you download the correct version based on your Windows architecture (32-bit or 64-bit).

Step 2: Generate SSH Key Pair with PuttyGen

Now that you have PuttyGen installed, you can create your SSH key pair.

  1. Open PuttyGen.
  2. Click on the "Generate" button.
  3. Move your mouse around in the blank area to generate randomness.
  4. Once the key is generated, you will see the public key displayed in the window.

Important:

  • You can set a passphrase for added security. This is optional but recommended.

Step 3: Save Your SSH Key Pair

After generating your keys, you need to save them for future use.

  1. Click on "Save private key" and choose a location to save your private key file. Name it something recognizable (e.g., mykey.ppk).
  2. Copy the public key from the PuttyGen window. You will need this for the server.

Common Pitfall:

  • Do not share your private key. Keep it secure and only use it on trusted devices.

Step 4: Add Your Public Key to the Linux Server

To connect to your server using the SSH key, you need to add your public key to the server's authorized keys.

  1. Log in to your Linux server using an existing method (like password authentication).
  2. Open the terminal.
  3. Navigate to the .ssh directory:
    cd ~/.ssh
    
  4. If the authorized_keys file does not exist, create it:
    touch authorized_keys
    
  5. Open the authorized_keys file with a text editor (e.g., nano):
    nano authorized_keys
    
  6. Paste your public key into this file and save it.

Tip: Ensure the permissions of the .ssh directory and authorized_keys file are set correctly:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Step 5: Configure Putty to Use Your SSH Key

Now you need to configure Putty to use the key you just created.

  1. Open Putty.
  2. In the "Session" section, enter your server's hostname or IP address.
  3. In the left menu, expand "Connection" and then "SSH."
  4. Click on "Auth."
  5. Browse and select your private key file (mykey.ppk).
  6. Go back to the "Session" section and save your session by entering a name under "Saved Sessions" and clicking "Save."

Step 6: Connect to Your Server

With everything set up, you can now connect to your server.

  1. Select the session you saved in Putty.
  2. Click "Open" to initiate the connection.
  3. If prompted, enter your username.

Conclusion

You have successfully set up SSH keys on Windows using PuttyGen. This process allows for secure, password-less login to your Linux server. Remember to keep your private key secure and consider using a passphrase for additional protection.

For future connections, simply open your saved session in Putty, and you'll connect without needing to enter your password.