I am doing a permanent port forwarding via SSH. It is basically
while true; do
ssh <somewhere> \
-R <dst-port>:localhost:<src-port> \
-N -n -o ExitOnForwardFailure=yes
sleep 10
done
However, that is not very reliable. Sometimes, the port is not forwarded at all (I'm not sure if the connection is correctly alive but I can see the process on the client and it is running already for several hours), sometimes the connection is surely not alive anymore (because the network interface is down) but it takes very long (sometimes up to 30-60 minutes) to timeout.
How can I make that more reliable? I want to have a timeout of maybe a minute.
I just found this very related/similar question. However, the first answer indicates that ExitOnForwardFailure
should solve it but I already have that and it does not (I can see right now the running ssh
process with this option but the port is not forwarded).