Answers
Why a reverse SSH tunnel keeps dying, and how to keep remote Pis reachable
Mobile and NAT links drop idle connections without telling either side. Keepalives, a supervisor and an exit-on-failure setting fix most of it.
Asked on Raspberry Pi Forums, November 2023: “Reverse ssh tunnel suddenly stopped on multiple RPis”
Short answer
NAT boxes and mobile carriers forget idle connections after a few minutes, so the tunnel looks up on the Pi but goes nowhere. Send keepalives, make ssh exit when they fail, and let systemd restart it. When many Pis drop at once, look at what they share: the VPS, its sshd, or a changed host key.
Make the tunnel survive
A systemd unit on each Pi, instead of a script in rc.local:
[Service] ExecStart=/usr/bin/ssh -NT -o ServerAliveInterval=30 -o ServerAliveCountMax=3 \ -o ExitOnForwardFailure=yes -R 2222:localhost:22 tunnel@your-vps Restart=always RestartSec=15
ServerAliveIntervalkeeps the carrier from forgetting the connection, and ends ssh when the link is gone so systemd starts a new one.ExitOnForwardFailurematters after a drop: the VPS may still hold the old port 2222, and without it ssh stays connected with no tunnel.ClientAliveInterval 30in the VPS's sshd_config frees the port sooner.- Each Pi needs its own port; keep the list somewhere, because the port is the only name you have.
When many Pis drop at the same time
The Pis didn't all fail together; something they share did. Check the VPS first: was it rebooted, did its host key change (the Pis then refuse it), did a firewall or fail2ban rule block the carrier's shared addresses, or did the disk fill and stop sshd from logging in? journalctl -u ssh on the VPS usually says which.
Or skip the tunnel
Fieldhand's agent does the keepalive part for you: it learns how long each link can stay idle and sends a small heartbeat just before the carrier would drop it, reconnects with backoff, and you reach devices by name instead of by port. If a device does drop, you're alerted and the device page shows why. You can still use your own ssh client, with fh ssh pi@kiosk-14 (see CLI).
By Abner Souza, who builds Fieldhand. Updated 2026-10-23. Something wrong or out of date? Write to support@fieldhand.dev.
Something wrong or missing on this page? Tell us.