Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] ssh tunnel in background requires nohup?



Hi TLUGers,

    I've been scritching my head on this one and was hoping to find a more definitive
explanation from some ssh gurus here why I've been seeing a particular phenomenon with 
using ssh tunnels.

    I've been playing with ssh tunnels a little bit more and noticed I was having
troubles logging off from a host once I started up a tunnel on it then tried to exit.
Consider this use case example:


desktop$ ssh somehost
somehost$ ssh -f -n -N -L 8080:localhost:80  example@example.com
somehost$ exit
logout  <---- It sits here and hangs unless I terminate the ssh session forcibly
              from machine named desktop.


    I find this behavior extremely annoying since the manpage for ssh states the
following:

     -f      Requests ssh to go to background just before command execution.  
             This is useful if ssh is going to ask for passwords or passphrases, 
             but the user wants it in the background.  This implies -n.  The 
             recommended way to start X11 programs at a remote site is with 
             something like ssh -f host 
     -N      Do not execute a remote command.  This is useful for just forwarding ports
     -n      Redirects stdin from /dev/null (actually, prevents reading from 
             stdin).  This must be used when ssh is run in the background.

    From my understanding I should be able to use the -f -N and -n options to
get ssh to run in the background and I can go off and do other things including
logout and expect the tunnel to keep running.  

    So my questions to TLUG are:
1. If you try something similar do you have the same issues?
2. Is this distro-specific?  I've tested this on Debian Sarge, Ubuntu Feisty 
   and Ubuntu Dapper so perhaps it is something that is Debian-specific but
   I don't have enough linux distros available right now to test this thoroughly.
3. Why is this happening?  My guess is that the sshd or shell process tied to
   the machine you are trying to run the ssh tunnel from is waiting for some signal
   from the ssh tunnel process before it exits.
   
I am able to get around this by using the nohup command in front of the ssh tunnel
command but from I've gleaned from looking at various websites it should not 
be necessary.  I tested setting up a ssh tunnel with FreeBSD using the same
command and can confirm I can log off afterwards without it hanging so perhaps
this is yet another one of those annoying subtle Linux bugs.

Hints? 
Alain


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links