Guide

SSH key authentication explained

SSH key authentication proves who you are with a private key that never leaves your computer, instead of a password sent to the server. For a new key, generate Ed25519 with ssh-keygen and protect it with a passphrase.

Short answer

SSH key authentication uses a key pair. The public key is placed in ~/.ssh/authorized_keys on the server; the private key stays on your computer. At login the client signs data tied to that session with the private key and the server verifies the signature, so no secret is transmitted. Generate a key with ssh-keygen -t ed25519, give it a passphrase, and install the .pub file on the server.

This guide uses standard OpenSSH tools. Transputty, the Windows SSH tunnel manager this site belongs to, is in development with no public build yet; see the release status.

How does public-key authentication work?

  1. You generate a pair: a private key, which you keep, and a public key, which you can hand out freely.
  2. The public key is added to the authorized_keys file of your account on the server.
  3. When you connect, the client tells the server which public key it wants to use. If the server finds that key in authorized_keys, the client produces a signature with the private key over data that includes an identifier unique to this SSH session.
  4. The server verifies the signature with the public key. A valid signature proves the client holds the private key.

The private key never crosses the network, and because the signed data is bound to one session, a captured signature cannot be replayed elsewhere. This happens after the encrypted channel is established and after the server has proved its own identity.

Host keys and user keys are different things

People mix these up because both are "SSH keys".

Host key User key
Identifies The server, to you You, to the server
Private half lives On the server (/etc/ssh/ssh_host_*_key) On your computer (~/.ssh/id_ed25519)
Public half is recorded in Your known_hosts file The server's authorized_keys file
Checked On every connection, before you log in During login
When it is wrong "REMOTE HOST IDENTIFICATION HAS CHANGED" warning; possible interception "Permission denied (publickey)"

A changed host key deserves suspicion and a call to the server's administrator. A rejected user key is an ordinary configuration problem.

Which key type should I use?

Type ssh-keygen option Status today
Ed25519 -t ed25519 Recommended. Fixed size, fast, short public keys. Supported since OpenSSH 6.5
RSA -t rsa -b 4096 Fine for compatibility at 3072 bits or more. Must be used with SHA-2 signatures (rsa-sha2-256, rsa-sha2-512); OpenSSH has disabled the old SHA-1 ssh-rsa signature by default since version 8.8
ECDSA -t ecdsa -b 256 (or 384, 521) Acceptable and widely supported. Many people choose Ed25519 instead
DSA Obsolete. Limited to 1024 bits, disabled by default for years and removed from OpenSSH in version 10.0
Security-key types (ed25519-sk, ecdsa-sk) -t ed25519-sk Private key is bound to a FIDO hardware token. Needs OpenSSH 8.2 or later at both ends

An existing RSA key does not need replacing because of the SHA-1 change: the key is the same, and only the signature algorithm negotiated at login differs. Very old servers that offer nothing but ssh-rsa are the ones that cause trouble.

Generating a key with ssh-keygen

The command is the same on Windows (PowerShell or Command Prompt), macOS and Linux:

ssh-keygen -t ed25519 -C "deploy@workstation"

-C sets a comment, a label that helps you recognize the key later. You are asked where to save the key and for a passphrase. The defaults are:

System Private key Public key
macOS, Linux ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub
Windows C:\Users\you\.ssh\id_ed25519 C:\Users\you\.ssh\id_ed25519.pub

To see a key's fingerprint, or to add or change the passphrase on an existing key:

ssh-keygen -lf ~/.ssh/id_ed25519.pub
ssh-keygen -p -f ~/.ssh/id_ed25519

Why use a passphrase?

The passphrase encrypts the private key file. Without it, the file alone is enough to log in as you, so a stolen laptop, a backup or a synced folder becomes a stolen identity. With it, a thief also needs the passphrase. An agent, described below, removes the inconvenience of typing it repeatedly.

Installing the public key on the server

With ssh-copy-id (macOS with recent OpenSSH, Linux):

ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@bastion.example.com

It logs in with your password once and appends the key to ~/.ssh/authorized_keys, creating the file and folder with correct permissions.

The manual way from Windows, where ssh-copy-id is not included. For a Linux or macOS server, from PowerShell:

Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub |
  ssh deploy@bastion.example.com "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Then test with ssh deploy@bastion.example.com. You should be asked for the key's passphrase, not the account password. Always install the .pub file; the private key is never copied to a server.

If the server is itself Windows running OpenSSH Server, the file is C:\Users\username\.ssh\authorized_keys, and for members of the Administrators group the default configuration reads C:\ProgramData\ssh\administrators_authorized_keys instead. Microsoft's documentation covers the required permissions.

File permissions

OpenSSH refuses to use files that other users could read or change.

Path Mode
~/.ssh 700
Private key (id_ed25519) 600
authorized_keys on the server 600
Public key (.pub) 644 is fine

On the server, sshd with its default StrictModes yes also ignores authorized_keys when your home directory or ~/.ssh is writable by others, which shows up as an unexplained fall back to password login.

The Windows ACL issue

Windows has no mode bits, so OpenSSH checks the file's access control list. A private key that inherited permissions for other accounts produces WARNING: UNPROTECTED PRIVATE KEY FILE! and "Permissions for ... are too open", and the key is ignored. This is common for keys copied from another machine or stored outside your profile. Remove inherited permissions and grant access to yourself only (full control, so that ssh-keygen -p can still rewrite the file):

icacls "$env:USERPROFILE\.ssh\id_ed25519" /inheritance:r /grant:r "$($env:USERNAME):(F)"

ssh-agent: type the passphrase once

An SSH agent is a background program that holds unlocked private keys in memory and signs login requests for SSH clients. The clients never see the key itself.

Windows. The OpenSSH agent is a Windows service that is installed with the client and disabled by default. Check it, then enable and start it from an elevated PowerShell:

Get-Service ssh-agent
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent

Then, in a normal PowerShell window, add your key and list what the agent holds:

ssh-add $env:USERPROFILE\.ssh\id_ed25519
ssh-add -l

macOS and Linux. Desktop sessions usually start an agent for you. If not:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Agent forwarding (ssh -A) is a separate feature that lets a remote server use your local agent. It carries real risk on servers you do not fully trust, and ProxyJump removes most reasons to use it.

Key file formats and converting .ppk

A private key file can be recognized by its first line:

Format First line Notes
OpenSSH -----BEGIN OPENSSH PRIVATE KEY----- What current ssh-keygen writes for every key type
PEM, PKCS#1 -----BEGIN RSA PRIVATE KEY----- Older RSA keys; common from cloud consoles
PEM, SEC 1 -----BEGIN EC PRIVATE KEY----- Older ECDSA keys
PEM, PKCS#8 -----BEGIN PRIVATE KEY----- or -----BEGIN ENCRYPTED PRIVATE KEY----- Generic container
PuTTY PuTTY-User-Key-File-3: ... (or -2:) PuTTY's own .ppk format; holds both halves in one file

OpenSSH reads the first four and does not read .ppk. To convert a PuTTY key:

  1. Open PuTTYgen and click Load. Select the .ppk file and enter its passphrase.
  2. From the menu choose Conversions › Export OpenSSH key.
  3. Save under a new name, for example id_ed25519, in your .ssh folder. The exported key keeps the passphrase that was set in PuTTYgen.

The reverse direction is Conversions › Import key followed by "Save private key". A fuller walk-through is in how to use SSH private keys.

Password or key authentication?

Password Key
What the server stores A password hash Your public key, which is not secret
What is sent at login The password, inside the encrypted channel A signature; the private key stays local
Guessing attacks Possible whenever password login is enabled Not practical
If the server is compromised or impersonated The password you typed is exposed The attacker gains nothing reusable
Unattended use (scripts, automatic reconnection) Awkward: needs a stored password Natural: an agent or a dedicated key
What you must protect The password The private key file and its passphrase
Revoking access Change the password Remove one line from authorized_keys

Many administrators install keys and then turn password login off on the server with PasswordAuthentication no. Confirm key login works in a second session before doing that.

How Transputty handles keys

Transputty is in development and has no public build yet. This describes the current internal build for Windows 11, where "Key file" is one of four login methods beside "SSH agent", "Password" and "Interactive".

  • Accepted files. OpenSSH-format and PEM private keys, of type Ed25519, RSA (signing with SHA-2) or ECDSA. Transputty stores the path to the file and reads it when connecting. It does not copy or import the key.
  • The key card. After you choose a file, a card under the field shows the key type and size, whether it is passphrase-protected, its SHA256 fingerprint and its comment. It warns when the file is readable by other users, sits on a network share, a removable drive or a synced folder such as OneDrive or Dropbox, is in Temp or Downloads, or is an RSA key under 2048 bits.
  • Passphrases. An encrypted key brings up a prompt titled "Unlock" with the file's name, with three attempts. Ticking "Remember the passphrase (encrypted with Windows DPAPI)" stores it encrypted for your Windows account. The key file is read only after the server's host key has been verified, so an untrusted server never triggers a passphrase prompt.
  • Agent. The "SSH agent" method talks to the OpenSSH agent pipe on Windows. With a key file you can also tick "Also use the SSH agent (a key it holds is used without the passphrase)" and restrict the login to the agent key matching that file. The number of agent keys offered is capped, at 3 by default, to avoid failing on servers that count each offered key as a login attempt.
'Key file' selected in the editor. The key card shows an Ed25519 key in OpenSSH format, passphrase-protected, with its SHA256 fingerprint; this key has no comment and no warnings. The key is a throwaway made for the capture, and the host name is fictional.

Limits, stated plainly:

  • No .ppk files. The key card rejects them and points to the PuTTYgen conversion described above.
  • No Pageant. Only the OpenSSH agent pipe is used.
  • Agent support is conservative. It has been tested against a mock agent on a real named pipe, not yet against the real Windows ssh-agent service or against third-party agents, so it is not claimed to work with any of them.
  • No SSH certificates, no FIDO or security-key logins, no smart cards (PKCS#11), no Kerberos.
  • No DSA keys and no RFC 4716 (SSH2) key files.

More on how secrets are stored is on the security page, and the forwarding side is covered in the SSH port forwarding overview.

Common questions

Which SSH key type should I use?

Ed25519, unless a server you must reach is too old to support it. Ed25519 keys are small, fast and supported by OpenSSH since version 6.5. If you need RSA for compatibility, use at least 3072 bits and make sure the server accepts the SHA-2 signature algorithms. ECDSA is acceptable. DSA is obsolete and has been removed from OpenSSH.

How do I generate an SSH key on Windows?

Open PowerShell and run ssh-keygen -t ed25519. Windows 10 and 11 include the OpenSSH client, so nothing needs installing. Accept the default location, which is the .ssh folder in your user profile, and enter a passphrase. The command writes the private key id_ed25519 and the public key id_ed25519.pub.

Is SSH key authentication more secure than a password?

Generally, yes. A key cannot be guessed by trying common passwords, the private key is never sent to the server, and a server that accepts only keys is immune to password-guessing attacks. The trade-off is that the private key file must be protected: use a passphrase, and keep the file out of shared or synced folders.

What is the difference between a host key and a user key?

A host key identifies the server to you: the server proves it holds the key, and your client compares it with the one saved in known_hosts. A user key identifies you to the server: you prove you hold the private key matching a line in authorized_keys. They are separate key pairs with separate purposes.

How do I convert a PuTTY .ppk key to OpenSSH format?

Open PuTTYgen, click Load and choose the .ppk file, entering its passphrase if it has one. Then choose Conversions, Export OpenSSH key, and save the result under a new name. The exported file is a private key that OpenSSH and other tools can read. Keep the same passphrase on it, and delete copies you no longer need.

Sources and further reading

Transputty keeps SSH tunnels running on Windows

Local, remote and SOCKS5 forwards in one window, automatic reconnection with ports that stay bound, and a clear reason when something fails. In development; no public build yet.