How to Create SSH Keys on Windows for Secure Connections

Ever connect to remote servers or cloud services? Protect your access and data with SSH keys! This guide explores three simple methods to create SSH keys on your Windows machine.

What are SSH Keys?

Before diving in, it’s important to understand what SSH keys are and why they are beneficial. SSH stands for Secure Shell, a protocol used for secure remote login and data transfer. SSH keys act like a digital passport, granting access to authorized users while keeping unauthorized individuals out.

How to Create SSH Keys on Windows

Method 1: Using Command Prompt

  • Click Start, search for “Command Prompt,” and right-click on the result.
  • Select “Run as administrator” and click “Yes” to allow administrator access.
  • Type the following command and press Enter: ssh-keygen
  • Enter a desired file name and path (e.g., C:\Users\<username>\id_rsa) or press Enter to use the default location.
  • Enter a strong passphrase for added security and press Enter twice to skip creating one.
  • You’ll see a confirmation message with key details. Close the Command Prompt window using the exit command.

The key generation process will begin. Once complete, a confirmation message and key details will be displayed. You can now close the Command Prompt window.

Method 2: Using PuTTY

  1. Visit the official PuTTY website (https://www.putty.org/) to download and install the software.
  2. Open the Start menu, search for “PuTTYgen,” and select the application.
  3. In the “Type of key to generate” section, choose the desired key type (e.g., RSA) and enter the number of bits. Click “Generate” to start the key creation process.
  4. Click “Save public key” and choose a location to save the file. Rename the file with the key type and “.pub” extension (e.g., id_rsa.pub).
  5. Enter a strong passphrase and confirm it. Go to the “Conversions” tab, click “Export OpenSSH key,” choose a location, and save the private key with a similar name to the public key (e.g., id_rsa). Remember, private keys do not have file extensions.

Method 3: Using WSL (Windows Subsystem for Linux)

Prerequisites:

  • Windows 10 or 11
  • Administrator privileges

Installation:

  1. Click the Windows icon, search for “cmd,” right-click on “Command Prompt,” and select “Run as administrator.”
  2. Type wsl --status and press Enter. If not installed, proceed to the next step.
  3. Install WSL (Windows 10): Choose one of the following methods:
    • Microsoft Store: Search for “Windows Subsystem for Linux” and install it.
    • Command line: Type wsl --install and press Enter.
  4. Install a Linux distribution:
    • Microsoft Store: Search for and install your desired distribution (e.g., Ubuntu).
    • Command line: Use wsl --install -d <distribution_name>, replacing <distribution_name> with your choice (e.g., ubuntu).
  5. Enter your username and password when prompted.
  6. Type exit and press Enter in both the UNIX terminal and Command Prompt.

Generating SSH Keys:

  1. Click the Windows icon, search for “Ubuntu,” right-click, and select “Run as administrator.”
  2. Type ssh-keygen -t rsa -b 4096 and press Enter.
  3. Enter a path to save the key or press Enter to use the default location.
  4. Enter a strong passphrase twice (won’t be displayed while typing). Press Enter twice if you don’t want a passphrase (strongly discouraged).
  5. Type exit and press Enter to close the terminal.

Your SSH key pair will be located in the specified path (or the default location). You can distinguish the keys by their extensions:

  • Public key: .pub extension (e.g., id_rsa.pub)
  • Private key: No extension (e.g., id_rsa)

By following these steps, you can easily generate SSH keys on Windows and safeguard your remote connections.

Related: