If you cre­ate a reg­u­lar ssh port for­ward­ing like this

1
ssh –f –N –L 2010:localhost:22 _USER_@_OTHERHOST_

you’ll run into trou­bles if _OTHERHOST_ dies AFTER you setup the tun­nel. If you con­nect to localhost:2010 ssh will just wait until tcp time­out (on my machine this was 15 min­utes). An exam­ple how I con­nected to the _OTHERHOST_:

1
ssh –p 2010 _USER_@localhost _COMMAND_

There is a debian spe­cific option called SetupTimeOut:

Setup­Ti­me­Out
Nor­mally, ssh blocks indef­i­nitely whilst wait­ing to receive the
ssh ban­ner and other setup pro­to­col from the server, dur­ing the
ses­sion setup. This can cause ssh to hang under cer­tain cir­cum–
stances. If this option is set, ssh will give up if no data from
the server is received for the spec­i­fied num­ber of sec­onds. The
argu­ment must be an inte­ger. The default is 0 (dis­abled), or 300
if Batch­Mode is set. This is a Debian-specific option.

As I dont use debian I had to search another solu­tion, and here it is.
Enhanced tun­nel 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_