I found that my reverse SSH tunnel with autossh was not persistent.
The remote server reboots daily, with the local machine (to which the server's requests are forwarded) rebooting weekly. The tunnel was exiting each time the remote server restarted, meaning that it was only persistent for one day each week. My script to establish tunnels is now as follows:
#!/usr/bin/env bash
autossh -i ~/.ssh/id_rsa_tunnel -N -R *****:localhost:***** user@example.com &
autossh -i ~/.ssh/id_rsa_tunnel -N -R *****:localhost:***** user@example.com &
autossh -i ~/.ssh/id_rsa_tunnel -N -R *****:localhost:***** user@example.com &
autossh -i ~/.ssh/id_rsa_tunnel -N -R *****:localhost:***** user@example.com
I was running the script @reboot in a cron job, but I created a systemd service to run it and restart the script if the last connection fails:
[Unit]
Description=AutoSSH reverse SSH tunnel connection
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service sshd.service
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
Restart=on-failure
RestartSec=5s
User=pi
ExecStart=/home/pi/establish_tunnel
[Install]
WantedBy=multi-user.target
Hopefully this time it will stay up!