Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use a bash script which runs

/usr/bin/ssh -f -N -T -L8888: serveradmin@34.324.234.23

However, when I run the bash script, it waits.. I see the connection coming up but the script doesn't exit.. it's like it's waiting for the SSH process to finish, because when I manually kill it the bash script finishes as well.

Any ideas how to resolve this?

UPDATE: I have croned this script.. and the cron process is the one that becomes a zombie.. the actual scripts runs just fine, sorry about that, with ps -auxf I get:

root       597  0.0  0.7   2372   912 ?        Ss   Jul12   0:00 cron
root      2595  0.0  0.8   2552  1064 ?        S    02:09   0:00  \_ CRON
1001      2597  0.0  0.0      0     0 ?        Zs   02:09   0:00      \_ [sh] <defunct>
1001      2603  0.0  0.0      0     0 ?        Z    02:09   0:00      \_ [cron] <defunct>

and when I kill the ssh the defuncts disappear.. why would they become defunct?

share|improve this question
Why would your cron a ssh tunnel? Once it binds to the port, it will not be able to bind to it again. – Warner Jul 13 '10 at 14:00
I know, in the script I check if the tunnel is there already, if so do nothing.. if tunnel isn't there, bring it back up. This is to ensure the tunnel is always there.. – grandnasty Jul 13 '10 at 22:54

It seems you're trying to reimplement bits of autossh (apt-get install autossh).

Create a RSA key pair without a passphrase, install the public key on serveradmin@34.324.234.23 and try:

autossh -f -N -L8888: serveradmin@34.324.234.23
share|improve this answer

Remove the $.

workstation:~$ /usr/bin/ssh -f -N -T -L8888:
DSA host key for IP address '' not in list of known hosts.
workstation:~$ ps x | grep '\-f'
16170 ?        S      0:00 /usr/bin/ssh -f -N -T -L8888:

It goes straight to the background as you detail for me. I do have a keypair setup on my test server, however.

Do you already have something listening on 8888 on your local server? Do you already have an instance in the background?

share|improve this answer
thanks, however please see update. – grandnasty Jul 13 '10 at 0:13

Detach ssh process from your terminal:

  1. Send it to background

    /usr/bin/ssh -f -N -T -L8888: serveradmin@$34.324.234.23 &

  2. Nohup it

    nohup /usr/bin/ssh -f -N -T -L8888: serveradmin@$34.324.234.23

share|improve this answer
-f forks it to the background. – Warner Jul 12 '10 at 23:57
thanks, however please see update. – grandnasty Jul 13 '10 at 0:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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