Shutting down PC without killing SSH sessions
Solution 1
It sounds like you are running the screen session on your laptop. Then sshing from that screen session to the remote host(s). Shutting down the laptop will kill the local screen process, which in turn kills the ssh session.
What you want to do is ssh from your laptop to the remote host(s). Then start a screen session on the remote host. When you laptop is turned off, the ssh session will die, but the remote screen session will persist.
The next time you log in to the remote system, you can re-attach to the screen session with "screen -r" or if you have multiple screen sessions "screen -r < pid >".
Note: if you forgot to detach from the remote screen session before ssh is killed, the screen session may think it is still attached. In this case, you'll need to do "screen -dr < pid >" to detach the session first.
Solution 2
You can use nohup
to start a process that shall continue to run after you have logged out from a machine. That might be what you are looking for.
Solution 3
The point of screen is to run it on the server and detach with CTRL + A + D.
Solution 4
If you detatch the remote session in screen
, you can safely shut down your laptop.
Solution 5
Use nohup. Another choice to use VNC. Create VNC session on the server. Then connect to it whenever you work on. (More useful when the long process is using some GUI - an IDE for example)
Related videos on Youtube
Admin
Updated on September 17, 2022Comments
-
Admin over 1 year
I have some heavy, long processes running on remote Linux machines. I use my laptop to SSH to these machine and run the processes from my couch.
BUT, when I want to shutdown my laptop, I am in trouble since the remote processes are killed.
I did my research and found out that "screen" is a great solution for me, it is! (As long as I don't SHUTDOWN my laptop). Isn't there a way to "persist" the "screen" sessions so I can shut it down and then re-attach to a session?
-
Sam Miller almost 14 yearsAre you running screen on the remote Linux systems?
-
WeaponX86 almost 14 yearsis it possible to background the processes?
-
-
intuited almost 14 yearsNot sure if it's universally obvious that the screen session being detached from must be on the remote server.
-
intuited almost 14 yearsFor an already-running process, you can do ^Z and then
disown
to create what I believe is an equivalent effect.disown
is a bashism that may or may not be available on other shells. -
David Z almost 14 yearsBy the way, if I remember correctly, pressing
Ctrl+A
followed byD
when you're inscreen
will detach the screen session. -
detly almost 14 years+1 for
nohup
. The trouble with^Z
is that it pauses the process. There's no way to background a process but keep it running without a hiccup. -
Chris almost 14 years@David this is correct, you can also just close your terminal or ssh session and the screen will remain open. "screen -raAd" will reattach.
-
Alexander_Alvaer over 10 yearsHow can I start a screen session on the remote host?