Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

Generate SSH key using PuTTYgen

profile picture
Author
Aitor Andreu
Published
2022-05-10
Time to read
4 minutes reading time

Introduction

This tutorial will guide you on how to create an SSH key using PuTTYgen in your Windows PC and how to copy this key to connect to your server.

Prerequisites

  • Server running a Linux distribution
  • Local PC with Windows

Step 1 - Install PuTTYgen on Windows

The installation of PuTTY automatically comes with PuTTYgen. If you don't have PuTTY installed on your PC, it is enough to just download PuTTYgen (puttygen.exe — select 32 / 64 bits version according your PC, most probably 64-bit).

Step 2 - Run PuTTYgen

Double-click on the executable you just downloaded. This will open the PuTTY Key Generator window.

Executable puttygen.exe

Step 3 - Generate SSH key

  1. Press the "Generate" button
  2. Move your mouse around on the blank space to randomize your key
  3. Change the "Key comment" field to give your key a meaningful name like: "home", "office", "home-pc-i7", etc.
  4. RECOMMENDED: Enter a "Key Passphrase" to protect your SSH key. Note: This passphrase will be requested every time you try to connect using the generated SSH key.
  5. Save your public/private keys safely on your PC using the buttons "Save public key" and "Save private key". Remember the location you saved your key pair in.
  6. Copy the content of the field "Public key for pasting into OpenSSH authorized_keys file".

Step 4 - Copy public key to your server

Option 1: Copy key over FTP

  • Connect to your server using your preferred FTP Client (eg: FileZilla).
  • Edit file authorized_keys (location: /home/holu/.ssh/authorized_keys where "holu" is your username).
  • Append the content from your clipboard (done in last substep of Step 3) into the authorized_keys file.
  • Save.
  • Upload authorized_keys file.

Option 2: Copy key over SSH

Open your terminal / PuTTY client and type:

ssh-copy-id holu@your_server_ip

Step 5 - Use the key with PuTTY

If you use PuTTY, this is how you can add your key:

  • Open PuTTY
    • Go to Connection » SSH » Auth » Credentials
      • Click on Browse... and open your private SSH key file. The file probably ends with PPK (e.g. <your-key>.ppk).
      PuTTY »Credentials to authenticate with«
    • After the key is added, go back to Session
      • In the text box in the top left, enter your username and the IP address of the remote server
      • Select Open to connect to your server
      PuTTY »Saved Sessions«

Conclusion

You've created a new SSH key and copied it to your server, so you can now use it to easily and securely connect to your server. Another interesting tutorial is "How to login to your Hetzner instance with an SSH Key".

License: MIT
Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue
Try Hetzner Cloud

Get 20€ free credit!

Valid until: 31 December 2024 Valid for: 3 months and only for new customers
Get started
Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more