VPS

How to Use SSH Keys on Windows (PuTTY and Windows Terminal)

12 min read

How to Use SSH Keys on Windows (PuTTY and Windows Terminal)

The Short Answer

Typing a server password every time you connect is slow and insecure — passwords can be guessed, SSH keys effectively cannot. On modern Windows, the easiest path is the built-in OpenSSH client: open Windows Terminal (or PowerShell), run ssh-keygen -t ed25519, copy the public key to your server with ssh-copy-id, and log in with ssh user@server — no extra software needed. If you prefer a graphical tool, PuTTY with its PuTTYgen key generator is the classic alternative, and this guide covers both. Either way, the result is the same: password-free, phishing-proof logins, and the foundation for disabling password authentication entirely (see How to Secure Your VPS).

How SSH Keys Work (The 60-Second Version)

An SSH key pair is two mathematically linked files:

  • The private key stays on your computer and is never shared. Anyone holding it can log in as you, so protect it like a password — ideally with a passphrase.
  • The public key goes on the server, in ~/.ssh/authorized_keys. It is safe to share; it can only be used to verify your identity, never to impersonate you.

When you connect, the server encrypts a challenge with your public key. Only your private key can decrypt it, so a correct response proves you hold the private key — without the key ever crossing the network. This is why keys beat passwords: there is nothing to guess, intercept, or brute-force.

Windows 10 (version 1809 and later) and Windows 11 include an OpenSSH client by default. If ssh is not recognised, install it from Settings → Apps → Optional features → Add a feature → OpenSSH Client, or from an elevated PowerShell prompt:

Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

Step 1: Generate the key pair

Open Windows Terminal or PowerShell and run:

ssh-keygen -t ed25519 -C "[email protected]"

When asked for a file location, press Enter to accept the default (C:\Users\YourName\.ssh\id_ed25519). When asked for a passphrase, set one — it encrypts the private key, so a stolen laptop does not mean a stolen server. You will type the passphrase when you use the key (or use ssh-agent, Step 4, to type it once per session).

Ed25519 is the modern recommended key type: shorter keys, faster operations, and strong security. RSA (-t rsa -b 4096) is the fallback for very old servers that do not support Ed25519 — any Ubuntu 24.04 server supports Ed25519.

Step 2: Copy the public key to the server

The ssh-copy-id command exists on Windows 10/11 with the OpenSSH client installed:

ssh-copy-id user@YOUR_SERVER_IP

You will be asked for the server password one last time — this is the final password login. The command appends your public key to the server’s ~/.ssh/authorized_keys and sets the correct permissions.

If ssh-copy-id is not available on your Windows version, copy the key manually. First display the public key:

Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub

Then log in to the server with your password and add it:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys

Paste the public key as a single line, save, and fix permissions:

chmod 600 ~/.ssh/authorized_keys

Step 3: Test the key login

Open a new terminal window and log in — keep the old password session open as a safety net until the key login is proven:

ssh user@YOUR_SERVER_IP

If you set a passphrase, you will be asked for it (not the server password). If you log in without the server password, keys work. Only then should you disable password authentication on the server, following How to Secure Your VPS — and even then, test in a second window first.

Step 4: Use ssh-agent (type the passphrase once)

Without an agent, you type the passphrase on every connection. The SSH agent holds your unlocked key in memory for the session. Start it and add your key:

Start-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519

To make the agent start automatically, set its startup type once (elevated PowerShell):

Set-Service -Name ssh-agent -StartupType Automatic

After ssh-add, you type the passphrase once, and subsequent SSH connections in the session need no passphrase at all. The agent forgets the key when you log out of Windows or restart — a deliberate security property, not a bug.

Step 5: Simplify with an SSH config file

Typing ssh [email protected] every time is tedious and error-prone. Create a config file with friendly names:

notepad $env:USERPROFILE\.ssh\config
Host myvps
    HostName 203.0.113.10
    User deploy
    IdentityFile ~/.ssh/id_ed25519

Host webserver
    HostName 203.0.113.20
    User deploy
    Port 2222
    IdentityFile ~/.ssh/id_ed25519

Now ssh myvps connects with the right user, host, port and key. The config file also supports one key per server (IdentityFile per host), connection multiplexing, and jump hosts — all useful once you manage more than one server.

Method 2: PuTTY and PuTTYgen (Graphical)

PuTTY is the long-standing Windows SSH client. It uses its own key format (.ppk), so keys need converting — PuTTYgen handles both generation and conversion. Download PuTTY and PuTTYgen from the official site (putty.org) or install via winget:

winget install PuTTY.PuTTY

Step 1: Generate a key with PuTTYgen

  1. Open PuTTYgen.
  2. Set the key type to Ed25519 (at the bottom of the window) and the number of bits is fixed for Ed25519.
  3. Click Generate and move the mouse over the blank area to feed the random number generator.
  4. Set a key passphrase (and confirm it) — the same advice as Method 1 applies.
  5. Click Save private key and store the .ppk file somewhere safe, for example C:\Users\YourName\.ssh\myvps.ppk.
  6. Copy the public key from the text box at the top (labelled “Public key for pasting into OpenSSH authorized_keys file”) — you need this exact text for the server.

Step 2: Add the public key to the server

Log in to the server with PuTTY using your password, then paste the public key into authorized_keys exactly as in Method 1, Step 2:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "PASTE_THE_PUBLIC_KEY_HERE" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

Paste carefully: the key must be a single line with no line breaks. A wrapped or truncated key silently fails — the server ignores malformed lines without an error message.

Step 3: Configure PuTTY to use the key

  1. Open PuTTY. In the Session category, enter the server’s IP in “Host Name” and a name (for example myvps) in “Saved Sessions”, then click Save.
  2. Go to Connection → SSH → Auth → Credentials (in older PuTTY versions: Connection → SSH → Auth). Under “Private key file for authentication”, browse to your .ppk file.
  3. Go to Connection → Data and set “Auto-login username” to your server username.
  4. Return to Session, click Save again to store the settings, then click Open.

PuTTY connects, asks for the key passphrase, and logs you in without the server password. Future sessions are one double-click on the saved session name.

Step 4 (optional): Pageant, PuTTY’s key agent

Pageant is PuTTY’s equivalent of ssh-agent: it holds your unlocked key so PuTTY, WinSCP and other tools can use it without asking for the passphrase each time. Launch Pageant, add your .ppk file (entering the passphrase once), and leave it running in the system tray. For daily PuTTY use, Pageant plus a saved session is the smoothest workflow.

Converting Keys Between Formats

You may need the same key in both formats — OpenSSH for Windows Terminal, .ppk for PuTTY and WinSCP. PuTTYgen converts both ways:

  • OpenSSH → PuTTY: In PuTTYgen, File → Load private key, select your id_ed25519 file (choose “All Files” in the file dialog), then Save private key to create a .ppk.
  • PuTTY → OpenSSH: In PuTTYgen, load the .ppk, then Conversions → Export OpenSSH key to save an OpenSSH-format private key.

You can also generate one key pair and use it everywhere — there is no security benefit to separate keys per client application on the same computer. Separate keys per server are a different matter: if one server is compromised, its authorized_keys tells the attacker nothing about your other servers, but a single key used on many servers means one stolen private key opens them all. For most personal use, one key pair for all your servers is acceptable; for higher stakes, use one key pair per server or per group of servers.

Using Keys with SFTP and File Transfer

SSH keys work for file transfer too, since SFTP runs over SSH:

  • Windows Terminal: scp and sftp are included with the OpenSSH client. Copy a file to the server with scp file.txt myvps:/home/deploy/, using the config-file host name from Step 5.
  • WinSCP: the standard graphical SFTP client for Windows. Create a session, set the authentication to your .ppk file (or let Pageant provide the key), and drag files between panes. WinSCP also integrates with PuTTY for a one-click terminal.
  • VS Code: the Remote-SSH extension uses your OpenSSH config and keys automatically — open a remote folder on the VPS as if it were local. It reads the ~/.ssh/config file, so the host names from Step 5 appear in the Remote-SSH picker.

Troubleshooting

“Permission denied (publickey).” The server rejected the key. Check in order: the public key is in the server’s ~/.ssh/authorized_keys (as one unbroken line); the permissions are correct (~/.ssh is 700, authorized_keys is 600, and the home directory is not group-writable); the server’s sshd_config has PubkeyAuthentication yes; and the client is offering the right key (ssh -v user@server shows which keys are tried and why each is rejected — look for “Offering public key” lines).

“Server refused our key” (PuTTY). Same causes as above, plus PuTTY-specific ones: the key pasted into authorized_keys was the PuTTYgen public key text (correct) rather than the .ppk file contents (wrong — the .ppk is the private key in PuTTY’s format and will never work in authorized_keys), or the pasted key has line breaks. Also confirm PuTTY is loading the .ppk — check the session’s Auth settings and re-save.

“UNPROTECTED PRIVATE KEY FILE!” The private key file’s permissions are too open. On Windows this usually appears in WSL or Git Bash rather than native PowerShell. Fix it with chmod 600 ~/.ssh/id_ed25519 in that environment, or use icacls in PowerShell to restrict the file to your own user account.

The passphrase prompt appears every time. ssh-agent is not running or the key was not added. Run ssh-add -l — if it lists no keys, run Start-Service ssh-agent and ssh-add again. If the agent service is set to Manual startup, it stops when Windows restarts; set it to Automatic (Step 4).

“ssh-copy-id is not recognized.” Older Windows 10 builds ship an OpenSSH client without ssh-copy-id. Use the manual copy method (Step 2), or install Git for Windows, which bundles a full OpenSSH suite including ssh-copy-id in Git Bash.

The key works from one terminal but not another. Different terminals may use different SSH installations (native OpenSSH, Git Bash, WSL) with different home directories and different ~/.ssh folders. WSL’s ~/.ssh is inside the Linux filesystem, not C:\Users\YourName\.ssh. Decide which environment is your primary SSH client and keep your keys there; copy the public key to the server once and it works from every client that holds the matching private key.

Locked out after disabling password authentication. Every provider offers a web console (VNC) in its control panel — log in there with the server’s root password (or reset it via the panel) and fix authorized_keys or re-enable PasswordAuthentication in /etc/ssh/sshd_config. This is why the guides insist on testing the key login in a second window before disabling passwords.

Frequently Asked Questions

Do I need a different key for each server?

Not necessarily — one key pair can authenticate to many servers, and that is how most people start. Separate keys per server (or per server group) limit the damage if one private key is ever exposed. If you manage servers for different clients, use separate keys per client — it is both safer and cleaner to revoke access per client later.

What is the difference between Ed25519 and RSA keys?

Ed25519 is newer, faster, and uses much shorter keys (256 bits) for equivalent security. RSA with 4096 bits is the older standard and works everywhere, including very old servers. For any modern server, Ed25519 is the right default; use RSA only when a specific old system requires it.

Is a passphrase really necessary?

Strongly recommended. Without a passphrase, anyone who copies your private key file owns your servers — no second factor, no delay. With a passphrase, the stolen file is useless without the words. Combined with ssh-agent or Pageant, a passphrase costs you one typed phrase per Windows session and buys real protection.

Can I use the same key on my laptop and desktop?

You can copy the private key to a second computer, but each copy is another place the key can be stolen from. The cleaner approach is one key pair per device, with each device’s public key added to the server’s authorized_keys. Then losing a laptop means removing one line from the server, not re-keying everything.

How do I remove access for a lost device or a former team member?

Delete that device’s public key line from ~/.ssh/authorized_keys on every server it could access. The change takes effect immediately — no service restart needed. This is the main operational advantage of one key per device: revocation is a single line deletion.

Does using SSH keys mean I can disable password login entirely?

Yes — and you should, once key login is tested and working. With PasswordAuthentication no in sshd_config, brute-force password attacks become pointless: there is no password to guess. See How to Secure Your VPS for the full hardening sequence, of which SSH keys are the most important step.

The Bottom Line

Generate an Ed25519 key, copy the public half to the server, test the login in a second window, and let ssh-agent or Pageant handle the passphrase. Ten minutes of setup replaces every future password prompt with a secure, instant login — and unlocks the single most effective hardening step a VPS owner can take: turning password authentication off.

Leave a Reply

Your email address will not be published. Required fields are marked *