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.
Free developer tool
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.
ssh -N -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -L 5433:localhost:5432 deploy@bastion.example.comHost 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# 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 postgresautossh -M 0 -f -N -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -L 5433:localhost:5432 deploy@bastion.example.com# ~/.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-L 5433:localhost:5432Your computer listens on 5433. The server connects to localhost:5432, meaning its own Postgres. Typical for private databases behind a bastion.
-R 9000:localhost:3000The 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.
-D 1080A SOCKS5 proxy on your computer. Each app connection goes out from the server to any host, like a lightweight VPN for browsers and curl.
Choose local (-L) to reach a remote service, remote (-R) to expose a local one, or dynamic (-D) for a SOCKS proxy.
Fill in the user, server, port, optional key and jump host, then the listening port and the destination host and port.
Copy the ssh command, or the ~/.ssh/config block to start the tunnel later with ssh -N and an alias.
Run the test command, then use the autossh or systemd variant if the tunnel must survive dropped connections and reboots.
bind [127.0.0.1]:5433: Address already in useSomething 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 9000The 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 refusedThe 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 failedThe 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.
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.
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.
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.
-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.
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.
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.
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