Tutorial

How to manage multiple SSH tunnels on Windows

Several SSH tunnels stay manageable on Windows when every forward has a name and a planned local port. An OpenSSH config file with one Host block per server does that with no extra software.

Level
Intermediate
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
  • One or more SSH servers you can log in to, ideally with a key so that nothing prompts
  • A working single tunnel (see the first-tunnel tutorial)

Short answer

To manage multiple SSH tunnels on Windows, describe them once in %USERPROFILE%\.ssh\config: one Host block per server, one LocalForward line per tunnel, and a fixed local port for each. Then ssh -N prod-tunnels starts every forward in that block over a single connection. A tunnel manager adds status, reconnection and one-click control on top.

Transputty, described in the last part of this tutorial, is in development. Version 0.1 is an internal build with no public download yet; see release status. Everything before that section uses the OpenSSH client built into Windows, or PuTTY.

Why do multiple tunnels get messy?

One tunnel is one command. Five tunnels are five terminal or PuTTY windows that look identical in the taskbar, and three problems appear:

  • Forgotten ports. Was staging on 5433 or 5434? The answer lives in your shell history.
  • Port clashes. Two tunnels, or a tunnel and a local database, want the same port. One of them silently loses.
  • Silent death. A window gets closed, the laptop sleeps, and an app fails an hour later with "connection refused".

The fix for the first two is a written plan. The third needs something that watches the connection.

A naming and port convention that works for anyone

Decide the rule once and never think about it again. A simple scheme: keep the service's real port as the last four digits and put the environment in front.

Service Real port Production (1xxxx) Staging (2xxxx) Development (3xxxx)
PostgreSQL 5432 15432 25432 35432
MySQL 3306 13306 23306 33306
SQL Server 1433 11433 21433 31433
Redis 6379 16379 26379 36379
Web admin (HTTPS) 443 10443 20443 30443
RDP 3389 13389 23389 33389
SOCKS proxy 1080 1080 1081 1082

Rules that make the scheme hold:

  • Stay between 1024 and 49151. Ports below 1024 belong to well-known services, and Windows hands out 49152 to 65535 to outgoing connections (netsh int ipv4 show dynamicport tcp shows the range).
  • Never forward to the service's real port number locally. A local PostgreSQL on 5432 and a tunnel on 5432 will collide one day.
  • Name tunnels environment-service, such as prod-db and staging-redis, and use the same names everywhere: config file, PuTTY sessions, database client bookmarks.
  • If a port refuses to bind although nothing listens on it, check whether Windows has reserved it: netsh interface ipv4 show excludedportrange protocol=tcp.

How do I run several tunnels with plain OpenSSH?

Create or edit %USERPROFILE%\.ssh\config (a plain text file with no extension):

Host *
    ServerAliveInterval 30
    ServerAliveCountMax 3

Host prod-tunnels
    HostName bastion.example.com
    User deploy
    IdentityFile ~/.ssh/id_ed25519
    LocalForward 15432 db.internal:5432
    LocalForward 16379 cache.internal:6379
    LocalForward 10443 localhost:443

Host staging-tunnels
    HostName staging-bastion.example.com
    User deploy
    IdentityFile ~/.ssh/id_ed25519
    LocalForward 25432 db.internal:5432
    DynamicForward 1081

Start a whole block with one command, and leave the window open:

ssh -N prod-tunnels

All three production forwards share one SSH connection. To see how ssh reads a block without connecting, run ssh -G prod-tunnels and look at the localforward lines. ServerAliveInterval 30 makes ssh notice a dead connection after about 90 seconds instead of hanging.

ExitOnForwardFailure yes is often recommended so that ssh quits when a forward cannot be set up. It is worth having for remote forwards, but on Windows it did not catch a local port clash in our test (see the FAQ below), so keep the port plan.

Start several at once from PowerShell

Each server needs its own ssh process. The Windows OpenSSH client could not share connections with ControlMaster in the version we tested (9.5p2), so this is the practical pattern:

$tunnels = 'prod-tunnels', 'staging-tunnels'
foreach ($t in $tunnels) {
    Start-Process ssh -ArgumentList '-N', $t -WindowStyle Minimized
}

This suits key logins that do not prompt (see using SSH private keys); a password prompt would be hidden in a minimized window. To see what is listening and which process owns it:

netstat -ano | findstr "LISTENING" | findstr ":15432 :16379 :10443 :25432"
Get-Process ssh

Stop-Process -Name ssh ends every ssh process, including interactive sessions, so prefer closing the specific window or stopping one process ID. Nothing here restarts a tunnel that drops: when ssh exits, its ports are gone until you run it again.

PuTTY stores tunnels per saved session, so the same convention applies:

  1. Create one saved session per server, named like the Host blocks above (prod-tunnels).
  2. In Connection › SSH › Tunnels, add each forward: Source port 15432, Destination db.internal:5432, Local, then Add. Repeat for every tunnel; the Forwarded ports list shows them all.
  3. Return to Session, select the name and click Save.

Start a saved session without clicking through the dialog with putty.exe -load "prod-tunnels", or with no terminal window at all using plink:

plink.exe -N -load "prod-tunnels"

Each session is still its own window or process, and a dropped session takes its ports with it. The PuTTY comparison covers the differences in more detail.

How does Transputty handle many tunnels?

Transputty is a tunnel manager for Windows 11: it keeps every server and its forwards in one window. This is what the 0.1 build does, using the app's own terms.

  • Several rules per connection. A connection is one SSH server; each forward is a rule. In the editor, Add rule under Forwarding rules adds another Local, Remote or SOCKS rule to the same SSH connection.
  • Groups. Type a name in the editor's Group box. The sidebar lists Groups, and each group header in the list has Connect all in … and Disconnect all in … buttons. Groups cannot be renamed or reordered yet.
  • Favourites. Add to favourites in a row's right-click menu stars a connection. Starred connections appear under Favourites in the sidebar and in the tray flyout.
  • Filters and search. The sidebar has All connections, Active, Favourites, Needs attention and Recent. The search box ("Search connections, hosts, ports", Ctrl+F) matches names, hosts, users, groups, rule names, destinations and port numbers, so typing 15432 finds the tunnel.
  • Per-rule switches. Expand a connection with Show rules to get a switch on every rule, or use Turn off rule … in the row menu. One rule can be off while the others keep running.
  • Per-rule health. Connection state and rule state are separate. A connection can read "Connected" next to "1 of 4 rules failed", with the failing rule marked "Port in use" while the other three stay "Active". If the port is taken, a callout names the program holding it when Windows reports one, and offers the next free port.
  • Tray. Closing the window keeps tunnels running in the notification area by default. The tray flyout lists Needs attention, Favourites and Also active, with Disconnect all.
  • Start automatically. Per connection: Connect at launch in the editor's Behaviour section. For all starred connections: Settings › General › Connect favourites at launch. Open at login in the same place starts Transputty in the tray when you sign in.
  • Reconnection. With Reconnect automatically on (the default), a dropped connection is retried with backoff, and local ports stay open meanwhile, so clients keep their address. Two limits: a login that needs a one-time code asks you again on every reconnect, and a remote (-R) rule can stay failed after a reconnect until you click Retry. SSH tunnel keeps disconnecting has the details, and automatic reconnection the background.
Connections in groups, one expanded to show a switch per rule. It reads 'Connected' and '1 of 2 rules failed': one rule is marked 'Port in use' while the other stays 'Active'. The app is connected to local test servers with fictional host names.

Moving an existing setup across has one limit worth knowing: Transputty can import %USERPROFILE%\.ssh\config, including LocalForward lines, but only from the Welcome page, which is shown while there are no connections. An imported host follows its StrictHostKeyChecking setting: with accept-new (or no, which is imported as accept-new with a warning) Transputty saves an unknown server's first key without asking, where a connection created in the app always asks. A changed key is blocked in every case. Transputty does not read PuTTY sessions.

Which approach should I use?

ssh config PuTTY sessions Transputty
Several forwards on one connection Yes Yes Yes
One place listing every tunnel The config file The session list The main window
See which forward failed Read each window Event Log per window Per-rule state
Reconnect after a drop No (rerun it) No (reopen it) Automatic, local ports stay open. One-time-code logins need you again
Start at login Your own script Your own shortcut Open at login
Available today Yes, built in Yes No: in development

A config file plus the port table is a sound setup for a handful of tunnels. A manager earns its place when tunnels must stay up unattended. The SSH tunnel manager overview describes that category, and local port already in use covers clashes in depth.

Common questions

How do I open several SSH tunnels with one command?

Put them in one Host block of your OpenSSH config file as LocalForward, RemoteForward or DynamicForward lines, then run ssh -N followed by the Host name. One SSH connection carries all of that block's forwards. You can also repeat -L on the command line: ssh -N -L 15432:db.internal:5432 -L 18080:localhost:80 deploy@bastion.example.com.

Does ControlMaster connection sharing work with OpenSSH on Windows?

Not with the OpenSSH client that ships in Windows, as far as we could verify. With OpenSSH_for_Windows 9.5p2, a command using ControlMaster and ControlPath failed with 'getsockname failed: Not a socket'. Plan on one ssh process per server instead of sharing a master connection. A later release may change this; test your own version.

Which local ports should I use for SSH tunnels on Windows?

Use ports between 1024 and 49151 and give each environment its own block, for example 15432 for production PostgreSQL and 25432 for staging. Avoid 49152 to 65535, which Windows uses for outgoing connections, and avoid the service's real port if that service might also run on your PC.

Will Windows warn me when two SSH tunnels use the same local port?

Do not count on it. In our test with OpenSSH_for_Windows 9.5p2, a second ssh process that asked for a local port already held by another ssh process started without an error, even with ExitOnForwardFailure=yes, and netstat showed both listening. A port plan and a netstat check are more reliable than waiting for an error message.

How this tutorial was checked

2026-11-26: A config Host block with two LocalForward lines and a DynamicForward was run on Windows 11 with the built-in client (OpenSSH_for_Windows 9.5p2), and all three forwards carried traffic. The server was the Transputty project's own test SSH server on the same PC, not a real OpenSSH sshd. Also run: two ssh.exe processes asking for the same local port (both listened, with no error), ControlMaster (it failed with 'getsockname failed: Not a socket'), Start-Process ssh, netstat and the netsh excluded-port listing. The PuTTY and plink steps are from the PuTTY manual and were not run. The Transputty features are described from the 0.1 source code and its on-screen text and were not exercised in the app.

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.