Tutorial
How to set up SSH local port forwarding
To set up SSH local port forwarding, run ssh -N -L with a local port, then the destination host and port as the SSH server sees them. Three worked examples follow, each with the OpenSSH command, the config-file form, PuTTY's fields and the Transputty rule.
- Level
- Beginner
- Reading time
- 7 min
- Applies to
- Windows, OpenSSH command line
- Transputty steps checked against
- Transputty 0.1 (development build, not released)
Before you start
- An SSH client: OpenSSH (built into Windows 11, macOS and Linux) or PuTTY
- An SSH server you can log in to that allows TCP forwarding (the OpenSSH default)
- The destination's host name and port as seen from that SSH server
Short answer
SSH local port forwarding is set up with ssh -N -L LOCALPORT:DESTHOST:DESTPORT user@server. For example, ssh -N -L 5433:db.internal:5432 deploy@bastion.example.com makes 127.0.0.1:5433 on your computer reach PostgreSQL on db.internal through the bastion. Leave the command running and point your client at 127.0.0.1:5433.
This is the hands-on companion to the local port forwarding guide, which explains how it works. Transputty, shown alongside OpenSSH and PuTTY here, is in development with no public build yet; see release status. If this is your first tunnel, start with your first SSH tunnel on Windows.
The pattern behind every example
ssh -N -L [bind_address:]LOCALPORT:DESTHOST:DESTPORT user@sshserver
- LOCALPORT is opened on your computer.
- DESTHOST:DESTPORT is where the SSH server connects. The server resolves the name, so
localhostmeans the SSH server itself. - -N forwards without starting a remote shell. The command then sits silently until you stop it.
The same four values appear in every tool:
| OpenSSH | ssh config | PuTTY (Connection › SSH › Tunnels) | Transputty rule |
|---|---|---|---|
-L |
LocalForward |
Local | Kind: "Local (-L)" |
| LOCALPORT | first argument | Source port | Port (next to Listen address) |
| DESTHOST:DESTPORT | second argument | Destination | Destination host and Port |
Example 1: a web admin page on the server itself
A monitoring page listens on port 80 of bastion.example.com, but only on the server's loopback address (127.0.0.1, which only programs on the server itself can reach).
ssh -N -L 8080:localhost:80 deploy@bastion.example.com
Config-file equivalent (~/.ssh/config, on Windows %USERPROFILE%\.ssh\config), started with ssh -N bastion-web:
Host bastion-web
HostName bastion.example.com
User deploy
LocalForward 8080 localhost:80
PuTTY: Source port 8080, Destination localhost:80, Local, then Add. The list shows L8080 localhost:80.
Transputty: in the connection editor, under Forwarding rules: Kind "Local (-L)", Listen address 127.0.0.1, Port 8080, Destination host localhost, Port 80. A rule created with Add rule already starts with exactly these values (or the next free port after 8080).
Verify:
curl.exe -I http://localhost:8080/
You should get the page's HTTP response headers. Then open http://localhost:8080 in a browser.
Example 2: a database on a private host behind a bastion
PostgreSQL runs on db.internal, which only the bastion can reach. A bastion (or jump host) is the one server you are allowed to SSH into, which can in turn reach the private machines.
ssh -N -L 5433:db.internal:5432 deploy@bastion.example.com
Host prod-db
HostName bastion.example.com
User deploy
LocalForward 5433 db.internal:5432
PuTTY: Source port 5433, Destination db.internal:5432, Local, Add.
Transputty: pick the PostgreSQL preset in a new connection (it creates a rule from 127.0.0.1:5432 to localhost:5432, or the next free port if 5432 is taken), then set Port to 5433 and Destination host to db.internal.
Verify with the database's own client, connecting to the local end:
psql -h 127.0.0.1 -p 5433 -U app appdb
The connection from the bastion to db.internal is ordinary PostgreSQL traffic and is not encrypted by SSH; only the part between you and the bastion is. Database specifics, such as sslmode and pg_hba.conf, are in the PostgreSQL tunnel tutorial; there are matching ones for MySQL and SQL Server.
Example 3: RDP to an internal Windows machine
A Windows PC at 10.0.5.20 accepts Remote Desktop on port 3389 inside the office network.
ssh -N -L 13389:10.0.5.20:3389 deploy@bastion.example.com
Host office-rdp
HostName bastion.example.com
User deploy
LocalForward 13389 10.0.5.20:3389
PuTTY: Source port 13389, Destination 10.0.5.20:3389, Local, Add.
Transputty: the RDP preset creates a rule from 127.0.0.1:13389 to localhost:3389, with the note "Listens on 13389, so it never clashes with this PC's own Remote Desktop on 3389." Change Destination host to 10.0.5.20.
Verify: start Remote Desktop Connection against the local end:
mstsc /v:localhost:13389
Do not use local port 3389 on a Windows PC: its own Remote Desktop service may already hold it. RDP through this forward is TCP only; SSH does not forward UDP.
How do I choose the local port?
- Use 1024 to 49151. Windows assigns 49152 and above to outgoing connections.
- Do not reuse the service's real port if the same service could run locally.
- Keep the number recognisable: 5433 or 15432 for PostgreSQL, 13389 for RDP, 8080 or 8443 for web.
- In Transputty you can leave the rule's Port empty (the field shows "auto") and a free port is picked for you. Presets and Add rule also skip ports that are already in use.
Which address does the forward listen on?
By default, only loopback: programs on your own computer can connect, nobody else. You can state it explicitly:
ssh -N -L 127.0.0.1:5433:db.internal:5432 deploy@bastion.example.com
On Windows, ssh listened on both 127.0.0.1 and [::1] in our test when no address was given, so localhost and 127.0.0.1 both worked in clients. A bind address of 0.0.0.0, or GatewayPorts yes in your config, makes the port reachable from your network. That hands your access to the database to every device that can reach your computer, so do it only on purpose. Transputty's editor refuses a listen address that is not loopback.
How do I check that it is listening?
Windows:
netstat -ano | findstr :5433
Test-NetConnection 127.0.0.1 -Port 5433
Look for a LISTENING line; the last column is the process ID, which tasklist /fi "PID eq 1234" turns into a program name. TcpTestSucceeded : True confirms the port accepts connections.
Linux:
ss -ltnp | grep 5433
A listening port only proves the local end. If the client connects and is then cut off, and ssh prints channel 2: open failed: connect failed: Connection refused, the server could not reach the destination: see SSH tunnel "connection refused". If another program already has the port, see local port already in use.
How do I stop the forward?
- OpenSSH: Ctrl+C in its window. If it runs in the background, find the process ID with
netstat -ano | findstr :5433and runStop-Process -Id 1234(Windows) orkill 1234(Linux, macOS). - PuTTY: close the session window.
- Transputty: click Disconnect in the toolbar or the Beacon on the row. To stop one forward and keep the others, turn off that rule's switch.
When ssh or PuTTY stops, the local port closes at once and clients get "connection refused". To go the other way and publish a local service on the server, continue with remote port forwarding.
Common questions
What is the syntax of ssh -L?
ssh -L [bind_address:]port:host:hostport user@server. The first port is opened on your computer. host and hostport name the destination, and they are resolved by the SSH server, not by your computer. Without a bind address, the port listens on loopback only unless GatewayPorts is set. Add -N to forward without opening a shell.
Which local port should I choose for a forward?
Any free port from 1024 to 49151. Avoid the service's own port number if that service might run on your computer too: forward a remote PostgreSQL to 5433 or 15432 rather than 5432, and RDP to 13389 rather than 3389, which Windows itself uses for Remote Desktop.
Can other computers on my network use my local forward?
Not by default. OpenSSH binds a local forward to the loopback address, so only programs on your own computer can connect. Writing a bind address such as 0.0.0.0 or setting GatewayPorts yes opens it to the network, which exposes the destination to anyone who can reach your computer. Transputty (in development, no public build yet) accepts only loopback listen addresses in its editor.
How do I check that a local port forward is listening?
On Windows run netstat -ano | findstr :8080 and look for a LISTENING line; the last column is the process ID of ssh. Test-NetConnection 127.0.0.1 -Port 8080 should report TcpTestSucceeded True. On Linux use ss -ltnp and look for the port.
How this tutorial was checked
2026-11-26: A local forward was run on Windows 11 with the built-in client (OpenSSH_for_Windows 9.5p2), both from the command line and from a LocalForward config entry. A web page was fetched through it with curl.exe, and the listener was checked with netstat and Test-NetConnection before and after stopping ssh. The server was the Transputty project's own test SSH server on the same PC, not a real OpenSSH sshd. The three example commands use fictional hosts, so they were checked for syntax with ssh -G and not connected. Not run: psql, mstsc and ss. The PuTTY fields are from the PuTTY manual and were not run. The Transputty rule fields and presets were checked against the 0.1 source code, not clicked through 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.