For me when a ssh
tunnel disconnects it takes awhile for the connection to reset so the ssh
process continues to block leaving me with no active tunnels and I don't know why. A workaround solution is to put ssh
into the background with -f
and to spawn new connections without waiting for old connections to reset. The -o ExitOnForwardFailure=yes
can be used to limt the number of new processes. The -o ServerAliveInterval=60
improves the reliability of your current connection.
You can repeat the ssh
command frequently, say, in a cron
, or, in a loop in your script, for example, in the following, we run the ssh
command every 3 minutes:
while (1)
do
ssh -f user@hostname -Rport:host:hostport -N -o ExitOnForwardFailure=yes -o ServerAliveInterval=60
sleep 180
done