Run processes when not logged-in with SSH

Scenario: I want to run a process on a remote computer, but don’t want to keep the SSH connection open during its execution. Even using the & after a command does not make a running process presist / survive a SSH disconnect. For these cases you can use screen.

When logged-in in a remote computer, just start

This will open a new console inside the console. Now just start whatever task you want to execute and dispatch the screen then with Ctrl + d. Now you are back in the initial console and you can safely disconnect the SSH connection without worrying about the task running inside the screen-console. When you return, you can invoke:

This will list all the screens you have created. Now to reconnect to a certain screen using:

Where [screen name] is the name of the screen to resume (if you have multiple of them, just use the tab-extension). If you have trouble with a process running inside a screen just type Ctrl + k, which kills the screen.

A usual use case: I am in the office and start a process which will run into the night. Now instead of running it directly in my terminal, I run it inside a screen. Advantage: I can log out, having my task running in the background. I can reattach the screen from home in the night and check the results.

Leave a Reply

Your email address will not be published. Required fields are marked *