It's a time cost heavily job when compile something on server. But, my VPS ssh connection is unstable. Connection will be lost in about 10 minutes. How can I let my command continue run when ssh connection lost ?
Asked
Active
Viewed 2,674 times
0
-
1Have you tried `nohup`? `nohup command &` should do it. – codeforester Sep 18 '17 at 03:37
-
Can you use `screen`? it allows you to open a virtual terminal, which can be attached or detached at will. virtual terminals are not lost when you disconnect from a session, so you can come back and reconnect later. `screen -dmS fubar` will make a screen called fubar; `screen -r fubar` attaches to the screen, and pressing Ctrl+a, then d will detach. – Guest Sep 18 '17 at 03:37
-
You can install ```tmux``` on your server, that's a console GUI solution, comfortable to work with. – Patrick Portal Sep 18 '17 at 15:25
2 Answers
1
A quick Google search pulled up the following 3 SO posts that should help:
- Linux: Prevent a background process from being stopped after closing SSH client
- Getting ssh to execute a command in the background on target machine
- Use SSH to start a background process on a remote server, and exit session
TL;DR - use nohup

hek2mgl
- 152,036
- 28
- 249
- 266

beaumontwebdev
- 301
- 2
- 4
1
If you have an unstable connection, the screen(1) command is your best solution. This keeps the terminal session alive when you get disconnected and allows you to log back in a reconnect with it, preserving the screen state and whatever else you had running. It may not be installed by default on your linux distribution (its not on Ubuntu), but is available in any package system.
There are useful tutorials in various places -- a web search for linux screen command gives many pointers.

Chris Dodd
- 119,907
- 13
- 134
- 226