If you create a regular ssh port forwarding like this
1 | ssh –f –N –L 2010:localhost:22 _USER_@_OTHERHOST_ |
you’ll run into troubles if _OTHERHOST_ dies AFTER you setup the tunnel. If you connect to localhost:2010 ssh will just wait until tcp timeout (on my machine this was 15 minutes). An example how I connected to the _OTHERHOST_:
1 | ssh –p 2010 _USER_@localhost _COMMAND_ |
There is a debian specific option called SetupTimeOut:
SetupTimeOut
Normally, ssh blocks indefinitely whilst waiting to receive the
ssh banner and other setup protocol from the server, during the
session setup. This can cause ssh to hang under certain circum–
stances. If this option is set, ssh will give up if no data from
the server is received for the specified number of seconds. The
argument must be an integer. The default is 0 (disabled), or 300
if BatchMode is set. This is a Debian-specific option.
As I dont use debian I had to search another solution, and here it is.
Enhanced tunnel setup:
1 | ssh –o BatchMode=yes –o ServerAliveInterval=5 –o TCPKeepAlive=yes –f –N –L 2010:localhost:22 _USER_@_OTHERHOST_ |
and the “client” command:
1 | ssh –o BatchMode=yes –o ConnectTimeout=5 –p 2010 _USER_@localhost _COMMAND_ |
