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

If I was running a command before the SSH connection was dropped, will the command continue executing?

share|improve this question
up vote 11 down vote accepted

In most cases, no. Processes will be sent a SIGHUP on loss of terminal. You can prefix a command with 'nohup' to ignore the signal. See:

share|improve this answer

I'll add another heplful suggestion to the thread, something I just learned few minutes ago:

If you already started a process that will take a long time (tar restore in my case), and forgot to include nohup in front of it, you can still prevent it from terminating on logoff.

Here are the steps:

  1. Press Ctrl + Z - this will suspend the job
  2. Enter disown -h %x, where x is the job number you get after suspending the job
  3. Execute bg to put the job in the background
  4. Exit the shell and go on with your life :).
share|improve this answer
+1, however I have found that the disown command is not necessary under bash on linux. I only need to bg the job, then log out, and the job continues running. – njahnke Jul 27 '12 at 16:48

Not generally, although not knowing what shell or even what OS you're running, it's tough to say. If you were running it under screen, for example, I think the behavior is to detach and continue running. Maybe some other shells have that as a configurable option.

share|improve this answer
+1 for mentioning screen. – jscott Feb 23 '10 at 20:46

As Warner says above, the child of the ssh daemon (that is the login shell and it's children) will get SIGHUP, but they won't get them instantly. There will be a delay, sometimes in minutes before the ssh daemon on the server side gives up on your connection. During that time the process will continue to run.

As Warner also said, the process can choose to ignore SIGHUP, in which case, it will continue to run until it has to request input and then find STDIN has closed.

share|improve this answer

Warner's answer is spot on. Alternately, you could also execute the command in the background, by appending an ampersand (&) to the end of the command.

share|improve this answer

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.