Linux – Shutting down PC without killing SSH sessions

gnu-screenlinuxssh

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?

Best Answer

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.

Related Question