SSH Key Generation with PuTTYgen
Master SSH key generation with PuTTYgen to establish secure, password-free authentication for your remote server connections.
What Are SSH Keys and Why They Matter
SSH keys are a pair of cryptographic keys used for authenticating to SSH servers as an alternative to password-based authentication. They consist of:
- Private Key: Kept secret on your local machine - never share this!
- Public Key: Placed on remote servers you want to access
Benefits of SSH Keys
- Enhanced Security: Much stronger than passwords, resistant to brute-force attacks
- Convenience: No need to type passwords for each connection
- Automation: Enable automated scripts and deployments
- Auditing: Easy to track which keys have access to which servers
- Revocable: Simply remove a public key to revoke access
PuTTYgen Basics
PuTTYgen is the key generation tool for PuTTY. It creates SSH key pairs and can convert between different key formats. The tool is included in the full PuTTY installation package.
Supported Key Types
- RSA: Most widely supported, use 2048-bit minimum (4096-bit recommended)
- ED25519: Modern, faster, and more secure - recommended for new keys
- ECDSA: Elliptic curve algorithm, good balance of security and performance
- DSA: Legacy format, not recommended (limited to 1024 bits)
Step-by-Step Key Generation Guide
Step 1: Open PuTTYgen
- Download PuTTYgen from the official PuTTY website if you haven't already
- Launch
puttygen.exe
- The "PuTTY Key Generator" window will open
Step 2: Choose Key Type (RSA/ED25519)
For RSA Keys:
- Select "RSA" in the "Parameters" section
- Set "Number of bits in a generated key" to 4096 (or at least 2048)
For ED25519 Keys (Recommended):
- Select "EdDSA" in the "Parameters" section
- Choose "Ed25519" from the curve dropdown
- Note: Bit length is fixed at 256 bits for ED25519
Step 3: Generate the Key
- Click the "Generate" button
- Move your mouse randomly over the blank area in the window
- This creates entropy (randomness) for the key generation
- Wait for the progress bar to complete
- Your new key pair will be displayed
Step 4: Add a Key Passphrase (Highly Recommended)
Why use a passphrase?
A passphrase protects your private key. Even if someone steals your key file, they cannot use it without the passphrase.
- Enter a strong passphrase in the "Key passphrase" field
- Re-enter it in the "Confirm passphrase" field
- Use a passphrase with at least 12 characters, including mixed case, numbers, and symbols
Step 5: Add Key Comment (Optional but Recommended)
In the "Key comment" field, enter a description like:
myname@work-laptop-2025
john.doe@company.com-production
This helps you identify keys later when managing multiple keys.
Step 6: Save Your Keys
⚠️ Important:
Save your private key BEFORE closing PuTTYgen. Once you close the window without saving, the key is lost forever and you'll need to generate a new one.
Save Private Key:
- Click "Save private key"
- If you didn't add a passphrase, you'll get a warning - click "Yes" only if you understand the risk
- Choose a secure location (e.g.,
C:\Users\YourName\.ssh\
) - Name it descriptively:
my-server-key.ppk
- The .ppk extension is PuTTY's private key format
Save Public Key:
- Click "Save public key"
- Save it in the same location as your private key
- Name it:
my-server-key-public.txt
Step 7: Copy the Public Key
In the PuTTYgen window, you'll see a text box labeled "Public key for pasting into OpenSSH authorized_keys file":
- Select all the text in this box
- Copy it (Ctrl+C)
- This is the exact format needed for your server's
authorized_keys
file
Using SSH Keys with Servers
Adding Your Public Key to a Server
Method 1: Manual Installation
- Connect to your server using PuTTY with password authentication
- Create the SSH directory if it doesn't exist:
mkdir -p ~/.ssh
chmod 700 ~/.ssh
- Edit the authorized_keys file:
nano ~/.ssh/authorized_keys
- Paste your public key (the text you copied from PuTTYgen)
- Save and exit (Ctrl+O, Enter, Ctrl+X in nano)
- Set correct permissions:
chmod 600 ~/.ssh/authorized_keys
Method 2: Using ssh-copy-id (if available)
If your system has ssh-copy-id, you can use it to automatically install your public key:
ssh-copy-id -i ~/.ssh/my-key.pub user@hostname
Configuring PuTTY to Use Your Private Key
- Open PuTTY
- Load your saved session or create a new one
- In the left panel, navigate to: Connection → SSH → Auth → Credentials
- Click "Browse" next to "Private key file for authentication"
- Select your .ppk private key file
- Go back to the Session category and click "Save"
- Click "Open" to connect
Troubleshooting Common Key Errors
Error: "Server refused our key"
Possible causes:
- Public key not correctly added to server's authorized_keys file
- Wrong file permissions on server
- Wrong username
Solutions:
- Verify the public key is correctly pasted (entire key on one line)
- Check permissions:
~/.ssh
should be 700,authorized_keys
should be 600 - Check server logs:
sudo tail -f /var/log/auth.log
(Ubuntu/Debian)
Error: "Unable to use key file"
Causes:
- File format is incorrect (not .ppk format)
- File is corrupted
Solution:
Use PuTTYgen to convert other key formats to .ppk: Load the key via Conversions → Import key, then save it as .ppk format.
Error: "Disconnected: No supported authentication methods available"
Causes:
- Server doesn't allow public key authentication
- No valid authentication method configured in PuTTY
Solution:
- Check server's
/etc/ssh/sshd_config
file - Ensure
PubkeyAuthentication yes
is set - Restart SSH service:
sudo systemctl restart sshd
Passphrase Issues
If you're repeatedly prompted for your passphrase:
- Use Pageant (PuTTY's authentication agent) to load your key once per session
- Pageant will cache your decrypted key in memory
- You'll only need to enter the passphrase once when loading the key into Pageant
Converting Key Formats
PuTTYgen can convert between different key formats:
OpenSSH to PuTTY (.ppk)
- Open PuTTYgen
- Click Conversions → Import key
- Select your OpenSSH private key (usually
id_rsa
orid_ed25519
) - Enter passphrase if required
- Click "Save private key" to save as .ppk
PuTTY to OpenSSH
- Open PuTTYgen
- Click "Load" and select your .ppk file
- Click Conversions → Export OpenSSH key
- Save the file (remove the extension for standard format)
Security Best Practices
- Always use passphrases: Protect your private keys with strong passphrases
- Use strong key lengths: 4096-bit RSA or ED25519
- Regular key rotation: Generate new keys periodically (annually recommended)
- One key per device: Generate separate keys for each computer/device
- Backup safely: Store backup copies of keys in encrypted storage
- Revoke compromised keys: Immediately remove public keys from servers if private key is compromised
- Use Pageant: Avoid storing unencrypted keys in memory
- Limit key access: Only add keys to authorized_keys for users who need them