Skip to content

SSH Tunnel & Port-Forward Generator

Reach a private database, share a local app or start a SOCKS proxy, with one ssh command.

Free · No signupBuilt entirely in your browser

SSH tunnel generator

Start with

Forwards

1 of 10
  1. Forward 1

    Listen on this computer
    Send it to, as 203.0.113.10 sees it

    localhost here means the server itself.

SSH server

Hostname, IP address or ~/.ssh/config alias.

Leave empty to use your SSH config or login name.

Options

What it does

  1. Connections to localhost:5432 on this computer go through 203.0.113.10 to localhost:5432, which is the server itself.

ssh -N \
  -L 5432:localhost:5432 \
  -o ServerAliveInterval=60 \
  -o ServerAliveCountMax=3 \
  -o ExitOnForwardFailure=yes \
  deploy@203.0.113.10

The tunnel stays up while the command runs. Press Ctrl+C to close it.

Then try it

  • Connect with psql
    psql -h 127.0.0.1 -p 5432 -U postgres
    Use 127.0.0.1 rather than localhost so the client connects over TCP.
Run it on this computer

For OpenSSH in Bash or Zsh on Linux, macOS or WSL. Run it on the machine that should open the local end of the tunnel.

Built in your browser. Servers, ports and key paths are not uploaded or saved. This tool writes text; it does not open a connection.

Tunnels without the flags

Save tunnels and start them with one click.

CtrlOps keeps local, remote and dynamic forwards as named tunnels, tests them first and can bring them up when it starts. Paste a command from this page straight in.

Explore Port ForwardingDownload for MacDownload for Windows

Keep it handy

Three directions,
one letter each.

The flag names where the listening port opens: -L on your machine, -R on the server, -D as a proxy.

The SSH forwarding types, their syntax and what they are for
TypeSyntaxUse it to
Local -L-L [bind:]port:host:hostportReach a remote or internal service from your machine
Remote -R-R [bind:]port:host:hostportExpose a local service on the SSH server
Dynamic -D-D [bind:]portRun a SOCKS proxy through the server
Socket -L-L port:/path/to.sockReach a Unix socket, such as Docker’s, on the server
Flags that go with a tunnel
FlagWhat it does
-NDo not run a remote command; just hold the tunnel open. Standard for pure forwards.
-fGo to the background after authenticating. Needs -N or a command.
-J hostConnect through a jump host (bastion) first.
-o ServerAliveInterval=60Send a keepalive every 60 seconds so idle tunnels are not dropped.
-o ExitOnForwardFailure=yesExit if a port cannot be opened, instead of staying up without it.

How SSH tunnels work

Private services.
Reached over SSH.

What is SSH tunneling?

SSH tunneling, or port forwarding, carries a TCP connection inside an encrypted SSH session. Instead of opening a database, dashboard or dev server to the internet, you reach it over SSH, so it stays private and encrypted. There are three directions, each a one-letter flag.

Local forwarding (-L): reach something remote

The most common kind. -L opens a port on your machine and forwards it to a destination the SSH server can reach. With ssh -L 5432:localhost:5432 user@server, a database client pointed at 127.0.0.1:5432 talks to Postgres on the server. The destination is resolved by the server, so localhost there means the server itself, and 10.0.1.20 means a machine on its private network. A Unix socket works as a destination too: -L 2375:/var/run/docker.sock lets your local docker command drive the server’s Docker.

Remote forwarding (-R): expose something local

The reverse. -R opens a port on the server and forwards it back to a destination your machine can reach. ssh -R 8080:localhost:3000 user@server makes the server’s port 8080 reach your local port 3000. By default the server listens only on its own loopback; to listen on a public address, its sshd_config needs GatewayPorts clientspecified or yes. Without it, OpenSSH binds loopback anyway and does not report an error.

Dynamic forwarding (-D): a SOCKS proxy

-D turns the SSH connection into a SOCKS5 proxy. With ssh -D 1080 user@server, any browser or app set to use 127.0.0.1:1080 as its SOCKS proxy connects out from the server, as if it were on the server’s network. Use curl --socks5-hostname so names are looked up by the server, too.

Keep tunnels up, and know when they fail

Firewalls and NAT drop idle connections, so ServerAliveInterval=60 sends a keepalive every minute and ServerAliveCountMax=3 gives up after three missed replies. ExitOnForwardFailure=yes makes ssh exit when a port is already in use, instead of connecting without it. One catch: a plain -L 5432 listens on both 127.0.0.1 and ::1, so if a local Postgres already holds 127.0.0.1:5432, ssh still starts on ::1 alone. Pick a free port such as 15432 when the service also runs on your machine. For a tunnel that must come back after a drop, use autossh, or the systemd service this tool writes, which starts it at boot and restarts it on failure. To make it a two-word command, save it as a named host with the SSH config generator.

Bind address and security

A forwarded port binds to localhost by default, so only your machine can use it. Binding to 0.0.0.0 opens it to your whole network, and the service behind it then has no SSH protection in front of it. For a SOCKS proxy that means anyone on the network can browse through your server. The SSH & Security guide covers the firewall and access rules worth having before you widen a bind address.

Read the OpenSSH ssh manual

SSH tunnel FAQ

SSH tunnels,
explained.

Keep working

Tools and guides for your next step.

Your privacy preferences. We use product analytics to improve CtrlOps. Google measurement runs without analytics cookies. Live chat stays off until you allow it. Cookie policy