Tutorial
How to use SSH private keys for tunnels
An SSH key lets a tunnel log in without a password. On Windows, ssh-keygen creates the key pair, one command installs the public half on the server, and ssh -i (or a tunnel manager) uses the private half.
- Level
- Beginner
- Reading time
- 8 min
- Applies to
- Windows, OpenSSH command line
- Transputty steps checked against
- Transputty 0.1 (development build, not released)
Before you start
- Windows 11 with the built-in OpenSSH client
- An SSH server you can currently log in to with a password, for example deploy@bastion.example.com
- PuTTYgen, only if you need to convert a .ppk key
Short answer
To use an SSH private key for tunnels on Windows, run ssh-keygen -t ed25519, append the contents of %USERPROFILE%\.ssh\id_ed25519.pub to ~/.ssh/authorized_keys on the server, and start the tunnel with ssh -N -i $env:USERPROFILE\.ssh\id_ed25519 -L 5433:db.internal:5432 deploy@bastion.example.com. The private key never leaves your PC.
Why keys beat passwords is covered in the SSH key authentication guide. Transputty, shown in the last section, is in development with no public build yet; see release status.
Step 1: generate an Ed25519 key
Open PowerShell and run:
ssh-keygen -t ed25519 -C "you@example.com"
Press Enter to accept the default location, then type a passphrase twice. The -C text is only a label that helps you recognise the key later. Two files appear:
| File | What it is | Share it? |
|---|---|---|
%USERPROFILE%\.ssh\id_ed25519 |
The private key, starting with -----BEGIN OPENSSH PRIVATE KEY----- |
Never |
%USERPROFILE%\.ssh\id_ed25519.pub |
The public key, one line starting with ssh-ed25519 |
Yes, it goes on servers |
Step 2: install the public key on the server
Windows has no ssh-copy-id. This PowerShell line does the same job; it asks for your server password one last time:
type $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"
It creates ~/.ssh on the server if needed, appends your public key to authorized_keys, and sets the permissions sshd insists on.
One Windows PowerShell quirk. If your console uses the UTF-8 code page (chcp prints 65001), Windows PowerShell 5.1 puts an invisible byte-order mark in front of piped text. We reproduced this; the key line then starts with stray bytes and the server will not recognise it. This variant sends the key as part of the command instead of through the pipe and avoids the problem:
$key = Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub
ssh deploy@bastion.example.com "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo '$key' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
This form puts the key line inside single quotes in a command that runs on the server, so it assumes the key's comment (the -C text) contains no apostrophe. If it does, paste the line into authorized_keys by hand.
Step 3: test the key
ssh -i $env:USERPROFILE\.ssh\id_ed25519 deploy@bastion.example.com
You should be asked for the key's passphrase (Enter passphrase for key ...), not the account password, and get a shell. If it still asks for the password, add -v and read which keys were offered, and on the server check that ~/.ssh/authorized_keys ends with one clean line beginning ssh-ed25519.
To confirm which key is which, print the fingerprint:
ssh-keygen -lf $env:USERPROFILE\.ssh\id_ed25519.pub
256 SHA256:4OiarQ1tPUl09K0KrpnYL5beFm0kLiZ4x4xnvNpbRVc you@example.com (ED25519)
Running the same command on the server against ~/.ssh/authorized_keys lists the fingerprints it accepts. Yours should be among them.
Step 4: use the key for a tunnel
ssh -N -i $env:USERPROFILE\.ssh\id_ed25519 -L 5433:db.internal:5432 deploy@bastion.example.com
A key named id_ed25519 in the default folder is tried automatically, so -i matters mainly for keys with other names. In %USERPROFILE%\.ssh\config the equivalent is:
Host prod-db
HostName bastion.example.com
User deploy
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
LocalForward 5433 db.internal:5432
IdentitiesOnly yes makes ssh offer only that key, which avoids "Too many authentication failures" when an agent holds many.
Step 5: stop typing the passphrase with the Windows ssh-agent
Windows includes an ssh-agent service that holds unlocked keys. It is disabled by default. Enable and start it once, in a PowerShell window opened with Run as administrator:
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
From now on ssh gets the key from the agent without a passphrase prompt, including the minimized tunnel windows described in managing multiple SSH tunnels. ssh-add -D removes all keys from the agent. If ssh-add answers Error connecting to agent: No such file or directory, the service is not running.
How do I fix "UNPROTECTED PRIVATE KEY FILE" on Windows?
OpenSSH refuses a private key that other accounts can read. This usually happens after copying a key from another PC, a USB stick or a download folder. The message looks like this:
Bad permissions. Try removing permissions for user: BUILTIN\\Users (S-1-5-32-545) on file C:/Users/you/keys/id_ed25519.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
This private key will be ignored.
Fix it in PowerShell. The first command stops the file inheriting permissions from its folder and grants your account full control; the second removes the group that ssh named:
$key = "$env:USERPROFILE\.ssh\id_ed25519"
icacls $key /inheritance:r /grant:r "$($env:USERNAME):(F)"
icacls $key /remove "BUILTIN\Users"
icacls $key
The last line prints the result. Entries for your own account, NT AUTHORITY\SYSTEM and BUILTIN\Administrators are accepted; anything else, such as Everyone or Authenticated Users, should be removed the same way. Repeat /remove for each name ssh complains about.
How do I convert a PuTTY .ppk key?
PuTTY stores keys in its own .ppk format. PuTTYgen, installed with PuTTY, converts in both directions.
From .ppk to OpenSSH (for ssh, and for Transputty):
- Start PuTTYgen and click Load. Choose the
.ppkfile and enter its passphrase. - Open the Conversions menu and choose Export OpenSSH key.
- Save it without an extension, for example as
%USERPROFILE%\.ssh\id_ed25519_from_putty. - Check it with
ssh-keygen -lfand, if ssh complains, fix its permissions as shown above.
From OpenSSH to .ppk (for PuTTY, plink and Pageant):
- In PuTTYgen, open Conversions and choose Import key. Select the OpenSSH private key.
- Click Save private key and save the
.ppkfile.
The exported file is protected with the passphrase shown in PuTTYgen's Key passphrase boxes at that moment. The public key is unchanged by conversion, so nothing needs to be updated on the server.
How do I use the key in Transputty?
These are the steps in the 0.1 development build.
- In the connection editor, under Authentication, choose Key file.
- Type the full path in the Key file box, or click Browse…, select the private key and click Use this key. The picker starts in Documents the first time and remembers the last folder afterwards; type
%USERPROFILE%\.sshin its address bar to jump to your keys. - Read the key card that appears under the field. Its first line gives the type, format and whether there is a passphrase, for example "ED25519 · OpenSSH · passphrase-protected". The second line is the SHA256 fingerprint and comment, which should match
ssh-keygen -lf. Warnings are marked ▲ (for example a key in Downloads, in a synced folder, or readable by other users) and errors ✕. - An error blocks saving. A
.ppkfile gives: "PuTTY .ppk keys aren't supported. In PuTTYgen: Load this key, then Conversions › Export OpenSSH key, and choose that file." Choosing the.pubfile or a DSA key is also an error. - Optional: tick Also use the SSH agent (a key it holds is used without the passphrase). Two more options then appear: Only the agent key matching this file (IdentitiesOnly) and Other agent keys to offer.
- Click Save & connect. For an encrypted key, the prompt "Unlock id_ed25519" asks for the passphrase, with up to three tries. Tick Remember the passphrase (encrypted with Windows DPAPI) to keep it for next time, then click Connect.
Transputty stores the key's path, not a copy of the key, and reads the file only after the server's host key has been verified.
Limits in 0.1: OpenSSH and PEM private keys of type Ed25519, RSA and ECDSA are supported. .ppk files, Pageant, SSH certificates and FIDO security keys are not. The agent option talks to the OpenSSH agent pipe and has so far been tested with a stand-in agent, not with the real Windows ssh-agent service. More detail is on the security page.
With the key in place, go back to your first SSH tunnel on Windows and run it without a password.
Common questions
Where does Windows store SSH keys?
In the .ssh folder of your user profile: %USERPROFILE%\.ssh, usually C:\Users\yourname\.ssh. ssh-keygen writes the private key to id_ed25519 and the public key to id_ed25519.pub there. The OpenSSH client looks in that folder automatically, so a key with the default name needs no -i option.
How do I fix WARNING: UNPROTECTED PRIVATE KEY FILE on Windows?
The key file's permissions let other accounts read it, so ssh ignores the key. In Command Prompt, remove inherited permissions and grant only yourself access: icacls path\to\key /inheritance:r /grant:r "%USERNAME%:(F)". If ssh still names a group such as BUILTIN\Users, remove it with icacls path\to\key /remove "BUILTIN\Users". The tutorial shows the PowerShell form.
Can I use a PuTTY .ppk key with OpenSSH or Transputty?
Not directly. OpenSSH and Transputty read OpenSSH and PEM private keys, not PuTTY's .ppk format. Open the .ppk in PuTTYgen with Load, then choose Conversions › Export OpenSSH key and save the result. The exported file works with ssh -i and can be chosen as the key file in Transputty, which is in development and has no public build yet.
Should my SSH key have a passphrase?
Yes, for any key that can reach something that matters. The passphrase encrypts the private key file, so a copied file is useless without it. To avoid typing it for every tunnel, load the key into an SSH agent once per session, or let a tunnel manager remember the passphrase in protected storage.
How do I check an SSH key's fingerprint?
Run ssh-keygen -lf followed by the key file, for example ssh-keygen -lf %USERPROFILE%\.ssh\id_ed25519.pub. It prints the key size, the SHA256 fingerprint, the comment and the type. The private and public files of one pair give the same fingerprint, which is how you confirm which key a server or an app is using.
How this tutorial was checked
2026-11-26: Run on Windows 11 with the built-in OpenSSH tools (9.5p2), in a temporary folder: creating the Ed25519 key, printing fingerprints with ssh-keygen -lf, reproducing the UNPROTECTED PRIVATE KEY FILE warning and clearing it with the icacls commands shown, ssh-add -l with the agent service stopped, and the byte-order mark that Windows PowerShell 5.1 adds to piped text. Not run: installing the key on a server and logging in with it, the tunnel command with -i (checked for syntax only), enabling the ssh-agent service and ssh-add, and PuTTYgen, whose steps are from the PuTTY manual. The Transputty steps were written from the 0.1 source code and its on-screen text and were not clicked through in the app.
Sources and further reading
- ssh-keygen(1) manual page, OpenBSD
- Key-based authentication in OpenSSH for Windows, Microsoft Learn
- icacls command reference, Microsoft Learn
- PuTTY manual, chapter 8: Using public keys for SSH authentication (PuTTYgen)
- ssh-add(1) manual page, OpenBSD
- sshd(8) manual page, OpenBSD (authorized_keys file format)
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.