Guide

Reverse tunnel: reach localhost from the internet without SSH plumbing

Reverse SSH tunnels let a machine behind a router or firewall accept connections from the internet: it dials out to a public server, and the server sends traffic back down that connection. Here is how the ssh -R command works, where a do-it-yourself tunnel gets fragile, and how to get the same result with one command and an HTTPS URL.

All docs

What a reverse tunnel is and when you need one#

A normal connection goes from a client to a server that has a public address. A reverse tunnel turns that around. The machine without a public address, such as your laptop behind a home router, dials out to a server on the internet and keeps the connection open. The server then accepts traffic on a public port and sends it back down that connection to a port on your machine.

It works where port forwarding does not, because an outbound connection passes through NAT, carrier-grade NAT and most corporate firewalls with no changes to the router. You need one when something on the internet has to reach a service that only listens on localhost:

  • A webhook provider such as Stripe or GitHub calling the handler you are writing.
  • A client or teammate looking at the dev server on your machine.
  • A phone or tablet testing a local build.
  • An OAuth provider redirecting back to a local app.
  • An AI agent in the cloud calling a local API or MCP server.

Reverse SSH tunneling is the classic way to build one, with nothing more than the ssh client and a server you can log in to.

The ssh -R command explained, with a VPS example#

The -R flag asks the SSH server to listen on a port and forward what arrives there back to your side. This is the whole of reverse tunnel SSH in one line:

Terminal
ssh -R 8080:localhost:3000 deploy@203.0.113.10
PartMeaning
-RRemote forward: the listening port is opened on the server, not on your machine.
8080The port the VPS listens on.
localhost:3000Where the traffic ends up, as seen from your machine: your dev server.
deploy@203.0.113.10The user and address of the VPS you connect to.

While that session is open, a request to port 8080 on the VPS reaches port 3000 on your laptop. This is the "ssh tunnel remote port to localhost" direction. The opposite flag, -L, opens the port on your machine and forwards to the remote side.

Out of the box you will find the port only answers on the VPS itself. By default sshd binds remote forwards to the loopback address. To accept connections from the internet, allow it in the server's /etc/ssh/sshd_config, restart sshd, and ask for all interfaces:

Text
# /etc/ssh/sshd_config on the VPS
GatewayPorts clientspecified
Terminal
# -N: no remote shell, only the forward
ssh -N -R 0.0.0.0:8080:localhost:3000 deploy@203.0.113.10

# From anywhere
curl http://203.0.113.10:8080/

You also have to open port 8080 in the VPS firewall and in any cloud security group in front of it.

Limits of DIY reverse SSH: keepalives, TLS, firewalls, a server#

The command is short. Keeping it working is the part that takes time, and it is what people mean by SSH plumbing.

Keepalives and reconnects#

An idle SSH session is dropped by routers along the way, and it dies when your laptop sleeps or changes network. Nothing restarts it. The usual fix is keepalive options plus a wrapper such as autossh or a systemd unit that reconnects:

Terminal
autossh -M 0 -N \
  -o ServerAliveInterval=30 -o ServerAliveCountMax=3 \
  -o ExitOnForwardFailure=yes \
  -R 0.0.0.0:8080:localhost:3000 deploy@203.0.113.10

ExitOnForwardFailure matters: without it, ssh stays connected when the remote port is already taken, and the tunnel looks alive while forwarding nothing.

TLS#

The SSH hop is encrypted, but the public side is plain HTTP on a bare port. Webhook providers and OAuth redirects expect https:// on a real hostname. That means a domain, a DNS record, and a reverse proxy such as Caddy or nginx on the VPS with a certificate that renews.

Firewall rules and exposure#

GatewayPorts changes what every SSH user on that server may expose, and the open port is reachable by anyone who scans it. Adding a password or an allowlist is more proxy configuration.

A server to babysit#

The VPS costs a few dollars a month and needs updates, SSH hardening and monitoring. You also get no record of the requests that came through unless you add logging yourself.

The same result with one OtterKit command and an HTTPS URL#

If what you are exposing speaks HTTP, a managed reverse tunnel does the same job with no server of your own. OtterKit's CLI dials out from your machine, the same way ssh -R does, and OtterKit's edge is the public side:

Terminal
npx otterkit login
npx otterkit tunnel 3000
Terminal
  ✓ Tunnel ready

  URL      https://tunnel-a1b2c3d4.otterkit.app
  Target   127.0.0.1:3000
  Rate     1 credit/hr · never more than 300/month

Each item on the list above is handled for you:

  • HTTPS. The URL has a certificate from the first request. There is no proxy to configure.
  • A stable address. --subdomain my-api reserves https://my-api.otterkit.app to your account, so the URL survives restarts.
  • Access control. --auth user:pass requires HTTP Basic auth. It is checked on your machine before anything reaches your server.
  • A record of traffic. Every request is captured locally, and inspect and replay let you read one and send it again.
  • Another host on your network. --host 192.168.1.20 forwards to a machine other than the one running the CLI.

OtterKit tunnels carry HTTP and HTTPS only. See tunnels for every option.

Daemon mode for tunnels that stay up#

The managed version of the autossh setup is one flag. --daemon runs the tunnel as a background process that keeps going after you close the terminal:

Terminal
# A stable background tunnel that runs until you stop it
npx otterkit tunnel 3000 --daemon --subdomain my-api --ttl never

# See what's running, then stop it by name
npx otterkit status
npx otterkit stop my-api

A tunnel stops by itself after 24 hours unless you pass another --ttl, which keeps a forgotten one from staying open. A tunnel can only answer while the process on your machine is running, the same as an SSH tunnel. If the goal is to catch webhooks while the laptop is closed, use an always-on webhook endpoint: OtterKit answers the sender and stores the event, and you replay it into your handler later. See daemon mode for the details.

Reverse SSH vs ngrok vs OtterKit: comparison table#

ngrok's column comes from its pricing page↗ and free plan limits↗, read on 23 November 2026. Check them for current numbers.

Reverse SSH (ssh -R)ngrokOtterKit
What you runssh on your machine, plus a VPS with sshd.The ngrok agent.npx otterkit. Needs Node.js.
A server of your ownYes.No.No.
HTTPS on a hostnameYour own domain, reverse proxy and certificate.Included.Included.
Stable URLYour VPS address or domain.One auto-assigned domain on Free. A name you choose starts on the $10 a month plan.Up to 10 reserved names per account, at no extra charge.
ReconnectsYour job: autossh or systemd.Handled by the agent.Handled by the CLI.
Raw TCPYes, any port.Yes.No. HTTP and HTTPS only.
Inspect and replay requestsNo.Yes.Yes, from the CLI, the MCP server, the console and the Mac app.
CostThe price of the VPS.Free plan with limits. Paid plans from $10 a month.$0.01 per connected hour, never more than $3 per tunnel in any 30 days. 10 free credits to start.
Driven by AI agentsAny agent that can run ssh.Agent CLI, SDKs and an API.MCP server with 23 tools, an agent skill, and await.

In short: use reverse SSH when you need TCP or already run the server, ngrok when you need TCP without one, and OtterKit for HTTP traffic you want inspected, replayed or handed to an agent. There is a longer comparison on the ngrok alternative page.

Get started#

A new account has 10 free credits, which is ten hours of tunnel time, and needs no card. There is nothing to install besides Node.js:

Terminal
npx otterkit login
npx otterkit tunnel 3000 --subdomain my-api

On a Mac, the free Mac app lists the ports that have something listening and opens a tunnel in one click.