Free developer tool

Free SSH Tunnel Command Builder

An SSH tunnel forwards a network port through an encrypted SSH connection, so you can reach a database, dashboard or dev server that is not open to the internet. This builder writes the exact ssh -L, ssh -R or ssh -D command, the matching ~/.ssh/config block, autossh and systemd keep-alive versions, and draws where the traffic goes. Everything runs in your browser; nothing is sent anywhere.

Opens a port on your computer. Anything that connects to it is carried through SSH and delivered to the destination, as seen from the SSH server. Use it to reach a database, admin panel or internal service that only the server can see.

Options

Where traffic flows

  1. Your computerlistens on localhost:5433
  2. SSH serverdeploy@bastion.example.com
  3. Destinationlocalhost:5432 (as seen from the server)

SSH command

ssh -N -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -L 5433:localhost:5432 deploy@bastion.example.com

~/.ssh/config block

Host db-tunnel
  HostName bastion.example.com
  User deploy
  LocalForward 5433 localhost:5432
  ServerAliveInterval 60
  ServerAliveCountMax 3
  ExitOnForwardFailure yes

# then start it with: ssh -N db-tunnel

Test the tunnel

# on your computer, connect to the local end:
nc -vz localhost 5433
# e.g. for Postgres: psql -h 127.0.0.1 -p 5433 -U postgres

autossh (reconnects)

autossh -M 0 -f -N -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -L 5433:localhost:5432 deploy@bastion.example.com

systemd user service

# ~/.config/systemd/user/ssh-tunnel-db-tunnel.service
[Unit]
Description=SSH Local (-L) tunnel db-tunnel
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/bin/ssh -N -o BatchMode=yes -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -L 5433:localhost:5432 deploy@bastion.example.com
Restart=always
RestartSec=10

[Install]
WantedBy=default.target

# systemctl --user daemon-reload && systemctl --user enable --now ssh-tunnel-db-tunnel

Local vs remote vs dynamic port forwarding

Local: -L 5433:localhost:5432

Your computer listens on 5433. The server connects to localhost:5432, meaning its own Postgres. Typical for private databases behind a bastion.

Remote: -R 9000:localhost:3000

The server listens on 9000 and sends traffic back to port 3000 on your computer. Typical for showing a local dev server or reaching a machine behind NAT.

Dynamic: -D 1080

A SOCKS5 proxy on your computer. Each app connection goes out from the server to any host, like a lightweight VPN for browsers and curl.

How to use the SSH tunnel builder

  1. 1. Pick the forwarding type

    Choose local (-L) to reach a remote service, remote (-R) to expose a local one, or dynamic (-D) for a SOCKS proxy.

  2. 2. Enter the SSH server and ports

    Fill in the user, server, port, optional key and jump host, then the listening port and the destination host and port.

  3. 3. Copy the command or config

    Copy the ssh command, or the ~/.ssh/config block to start the tunnel later with ssh -N and an alias.

  4. 4. Test and keep it running

    Run the test command, then use the autossh or systemd variant if the tunnel must survive dropped connections and reboots.

Flags and options explained

-N
Do not run a remote command or shell. The connection only carries forwards.
-f
Go to the background after logging in. Use with -N; stop it later with kill or pkill -f.
-J user@host
Hop through a jump host (ProxyJump). Separate several hops with commas.
ExitOnForwardFailure=yes
Quit if a port cannot be opened, instead of staying connected without the tunnel.
ServerAliveInterval=60
Send a keep-alive every 60 seconds; with ServerAliveCountMax=3, ssh exits after about 3 minutes of silence.
GatewayPorts
Server setting that decides whether -R ports may listen on addresses other than localhost.

Common SSH tunnel errors and fixes

  • bind [127.0.0.1]:5433: Address already in use

    Something on your computer already listens on that port, often an earlier tunnel. Find it with lsof -nP -iTCP:5433 -sTCP:LISTEN and stop it, or pick another local port.

  • Warning: remote port forwarding failed for listen port 9000

    The port is already taken on the server, below 1024 without root, or sshd blocks forwarding (AllowTcpForwarding no). Try another port or check sshd_config.

  • channel 2: open failed: connect failed: Connection refused

    The tunnel is up but nothing listens at the destination. For -L the destination is resolved on the server, so localhost means the server itself. Check the service and its port there.

  • channel 2: open failed: administratively prohibited: open failed

    The server does not allow this forward. sshd_config has AllowTcpForwarding no, a PermitOpen list, or the key has restrict / no-port-forwarding in authorized_keys.

  • Permission denied (publickey).

    Wrong user or key. Pass the right key with -i, check ssh-add -l lists it, and make sure its .pub is in ~/.ssh/authorized_keys on the server.

  • Privileged ports can only be forwarded by root.

    You asked to listen on a port below 1024. Use a higher local port such as 8080 or 5433.

SSH tunnel FAQ

What is an SSH tunnel?

An SSH tunnel carries a TCP connection inside an encrypted SSH session. ssh listens on a port at one end and forwards whatever connects to it to a host and port at the other end, so you can reach services that are not exposed to the internet.

What is the difference between ssh -L and ssh -R?

ssh -L (local forwarding) opens a port on your computer and delivers traffic to a destination reached from the server. ssh -R (remote or reverse forwarding) opens a port on the server and delivers traffic to a destination reached from your computer. -L pulls a remote service to you; -R pushes a local service to the server.

What does ssh -D do?

ssh -D starts a SOCKS5 proxy on a local port. Browsers or tools set to use that proxy send every connection through the SSH server, which connects onward to whatever host they ask for. It works like a simple VPN for apps that support SOCKS.

What does -N mean in an SSH tunnel command?

-N tells ssh not to run a remote command or open a shell. The session exists only to carry the forwarded ports. Add -f as well to send ssh to the background after it logs in.

How do I keep an SSH tunnel open?

Add -o ServerAliveInterval=60 -o ServerAliveCountMax=3 so ssh notices a dead link, and ExitOnForwardFailure=yes so it fails fast. To reconnect automatically, run it under autossh -M 0 or as a systemd service with Restart=always.

Why does my reverse tunnel only listen on localhost?

By default sshd binds remote forwards to the server's loopback address. To let other machines connect, set GatewayPorts yes or clientspecified in the server's sshd_config, restart sshd and give a bind address such as 0.0.0.0 in the -R spec.

Automate the steps around your tunnels

Opening a tunnel, running migrations and checking the result is a workflow. Tornic runs deterministic multi-step workflows on the Claude Code, Codex or Cursor CLI you already pay for.

Explore Tornic

Related free tools