Tutorial

How to Create an SSH Tunnel on Windows — Local, Remote & Dynamic

8 min read

An SSH tunnel is the simplest private tunnel you will ever build: it takes traffic from a port on your machine, wraps it inside your encrypted SSH connection, and releases it on the other side. No VPN software, no firewall changes, no extra keys — just the SSH access you already have. This guide walks through all three forwarding types on Windows, with commands you can copy, and finishes with a GUI shortcut that saves every tunnel as a reusable profile.

The three types, in one minute

TypeFlagDirectionTypical use
Local-LYour machine → remote networkReach a database or panel that only listens on localhost of the server
Remote-RRemote network → your machineShow a colleague your localhost dev server over the internet
Dynamic-DApp-level proxy via your serverRoute a browser through your server as a SOCKS5 proxy

All three travel through the same encrypted SSH session — the difference is only who listens where, and who connects to what.

1. Local forwarding (-L): reach a private service

The classic scenario: your PostgreSQL or MySQL database accepts connections only fromlocalhoston the server. From your Windows machine:

Command Prompt / PowerShell
ssh -L 15432:localhost:5432 user@server.example.com

# then connect your DB tool to:
host: 127.0.0.1   port: 15432   user/pass: your DB credentials

Read the flag left to right: 15432 is the local port you open, localhost:5432 is where traffic goes as seen from the server. Now your GUI database tool connects to port 15432 on your own machine and everything is piped through SSH to the real database. Kill the SSH session and the door closes automatically.

Forwarding to a third host

The target does not have to be the server itself. From the server you can reach anything the server can reach — an internal router, an IPMI card, a colleague's workstation:

ssh -L 8080:192.168.1.10:443 user@server.example.com
# https://127.0.0.1:8080 now lands on 192.168.1.10:443 (via the server)

2. Remote forwarding (-R): expose your local server

The reverse problem: you are building something on your Windows laptop and someone needs to open it from outside. Ask your public server to listen for you:

run on your Windows machine
ssh -R 9000:localhost:3000 user@server.example.com

# colleagues can now open http://server.example.com:9000
# and land on your laptop's localhost:3000 dev server

On the server, port 9000 starts listening and every request to it is tunnelled back to your machine. Two practical notes: keep the server port above 1024 (unless you control the server's firewall), and checkGatewayPortsin the server's sshd_config if you need the tunnel reachable on all interfaces, not just the server's loopback.

3. Dynamic forwarding (-D): your own SOCKS5 proxy

The most flexible trick of the three. Instead of mapping one port to one target, -D turns the SSH session into a SOCKS5 proxy, and each application decides where to send traffic:

PowerShell
ssh -D 1080 user@server.example.com

# then in your browser or OS proxy settings:
SOCKS5 host 127.0.0.1  port 1080

Browse with the server's point of view, reach an intranet dashboard through your jump box, or test geo-specific behaviour — all inside one SSH connection. DNS requests travel through the tunnel too when the client is set to resolve remotely.

Useful hardening flags

  • -N — do not open a shell; the session only carries the tunnel.
  • -C — compress traffic; helps text-heavy protocols over slow links.
  • -v — verbose output; your first stop when a tunnel misbehaves.
  • ServerAliveInterval 30 — keep NAT/firewalls from dropping idle tunnels.
ssh -N -C -L 15432:localhost:5432 user@server.example.com

The GUI way: saved tunnel profiles in NexSSH

Typing flags is fine the first time. The fourth time you re-type the same-Lline from a notes file, it stops being fine. NexSSH (free for Windows 10/11) gives every saved host a visual tunnel editor: add local, remote or dynamic entries to a profile, map the ports once, and from then on every connection to that server restores all its tunnels automatically — alongside a multi-tab terminal and a dual-pane SFTP pane. There is even a live monitoring dashboard, so you can watch the server you are tunnelling through.

Same rules under the hood, zero muscle memory required: pick the type, fill the three fields, save. The app builds the exact equivalent of the commands above.

Troubleshooting checklist

  • “bind: Address already in use” — another process owns your local port; pick another.
  • Connection refused at the target — the service listens on the server's loopback but not on the host you forwarded to; check the target address in your -L rule.
  • Remote tunnel not visible externally — set GatewayPorts yes (or clientspecified) in sshd_config and restart sshd.
  • Tunnel dies after a while — enable keep-alives (ServerAliveInterval) on both sides.

Wrap-up

Local, remote, dynamic: three flags, three directions, one encrypted connection. Once they are saved as profiles instead of notes-file archaeology, SSH tunnels stop being a party trick and become everyday infrastructure.