#Template SystemD service for a auto healing (reverse) SSH tunnel. #Place this to /etc/systemd/system/ folder. #Edit all values inside <> #/etc/systemd/system/ssh-persistent-tunnel.service #Edit the ports, remote user+host, and the key file. #In the authorized_keys file on the other system, use something like this: # [Unit] Description=SSH Persistent Tunnel After=network-online.target [Service] ExecStart=/usr/bin/ssh -T -N -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -R <1234:localhost:22> -o IdentityFile= ExecStop=/bin/kill -HUP $MAINPID ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure RestartSec=60 [Install] WantedBy=multi-user.target