I have a terminal connected to an external machine through ssh and have a process running in it. Is it possible move the execution to the background, so that I can close the ssh connection without the need to kill it? If so how?
Asked
Active
Viewed 6.3k times
2 Answers
123
Press control + Z, which will pause it and send it to the background. Then enter bg
to continue it's running in the background.
Alternatively, put a &
at the end of the command to run it in the background from the start.
This will just make it run in the background and once you log out it will still be killed. In order to keep it running after logout you will need to "disown" the process with disown -h
, so that the shell doesn't count it among your processes needing to be killed on logout. See this post for more details.

Caco
- 1,601
- 1
- 26
- 53

Jon Deaton
- 3,943
- 6
- 28
- 41
-
2Another way to do it is to add a `&` at the end of the command that runs the process which automatically starts it in the background. – Nir Alfasi Sep 18 '17 at 16:01
-
Thanks, it worked. Yes, I know that @alfasin. But I thought that the execution wouldn't take so much time. Thanks anyway. – Miguel Sep 18 '17 at 16:04
6
You can as well use the "screen" command which will keep running with processes inside it once you have detached from it.

Alain Star
- 69
- 1
- 2