I'm trying to establish the following chained ssh tunnel:

ssh -A -t gatewayuser@gatewayserver 'ssh -N -A -t -R 55520: user@dbserver' &

This is part of a shell script, I want the tunnel to be established in the background so the shell script can continue what it is doing. The shell script also uses:

trap 'kill $(jobs -p)' EXIT

To kill all child procs on exit.

When the above ssh runs, a process is established but it seems the chained reverse tunnel is immediately dropped (i.e. there is nothing listening to 55520 on the dbserver). How can I do this within the requirements above?


ssh seems to detect missing user input due to being started in the background and then suspends itself, the -t does not help.

You can have it read from stdin instead, e.g. via ssh [...] < /dev/null & or possibly /dev/zero.

  • Do you mean on the chained ssh or the outer one, can you give an example? Sorry if its a dumb question i'm fairly new to all this.
    – James
    Apr 14 '14 at 15:10
  • The outer ssh call, ssh [..] 'ssh -R [..]' < /dev/null & Apr 14 '14 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.