The title explains the question itself. My problem is every time I connect my VM machine through SSH it always timeouts after a period of time. So I'd like to let my Python script work on itself for like hours or days. Any advice? Thanks.
Asked
Active
Viewed 1,081 times
2

Wytrzymały Wiktor
- 11,492
- 5
- 29
- 37

Yiğit Mesci
- 65
- 9
-
3Take a look at https://www.tecmint.com/keep-remote-ssh-sessions-running-after-disconnection/amp/ – Puteri Feb 26 '22 at 15:08
-
See @ferregina-pelona for recommended user-level solutions. However, the correct solution is to run your program as a Linux service. https://stackoverflow.com/questions/1603109/how-to-make-a-python-script-run-like-a-service-or-daemon-in-linux Which solution to choose? That requires more information than your question provides on what you need to do and what your program does. – John Hanley Feb 26 '22 at 20:47
-
Thank u both. setsid solved the issue @FerreginaPelona ! – Yiğit Mesci Feb 27 '22 at 13:57
1 Answers
1
VM Instance will keep running even if your SSH times out.
You can keep the SSH session alive by adding following lines:
Host remotehost
HostName remotehost.com
ServerAliveInterval 240
to $HOME/.ssh/config
file.
There's a similar option in PuTTy.
To keep process alive after disconnecting, you have multiple options, including those already suggested in commnets:
Decision which one to choose depends on specifics of the task that is being performed by the script.

Sergiusz
- 1,175
- 4
- 13