Use screen to manage persistent sessions
GNU Screen is a command-line application that allows use of multiple virtual sessions within a single real terminal or remote session. Importantly, it allows for persistent running of command-line applications independent of the shell that initiated them program, meaning active applications can persist during disconnection.
This is just one of many things that screen is useful to accomplish! You can also use multiple screens to run concurrent applications on a remote or local server from a single terminal window.
Connect to the remote server, for example using ssh
On the remote server start
screen before any other commands. You will see the screen welcome text shown. Press any Space or Return to exit back to the shell.
You can now start any long running process that you wish to persist over the connection.
While this command is running you can now ‘detach’ the running screen from the active session by pressing
Ctrl-A followed by
Ctrl-D on the keyboard. You will notice that the active session returns to the point where you first typed screen.
Exit the running ssh session by typing
exit. Make a cup of tea. You can now reconnect to the server as before.
Back at the remote prompt you can re-attach the previously started screen to the current session.
You will see your command continued to run while you were away!
Get regular Shell tips & tutorials direct to your Inbox.