The moment I started working on remote servers was the moment I needed screen. Without it, closing your SSH session kills everything running in it. screen keeps your processes running after disconnect — you can reattach to the same session later and find everything exactly as you left it. The detach shortcut (Ctrl+A, Ctrl+D) is the key one to memorise.
Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| $ sudo apt install screen
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
byobu | screenie | iselect ncurses-term
The following NEW packages will be installed:
screen
0 upgraded, 1 newly installed, 0 to remove and 43 not upgraded.
Need to get 564 kB of archives.
After this operation, 1,010 kB of additional disk space will be used.
Get:1 http://za.archive.ubuntu.com/ubuntu bionic-updates/main amd64 screen amd64 4.6.2-1ubuntu1 [564 kB]
Fetched 564 kB in 3s (178 kB/s)
|
- View all screen processes id
1
2
3
4
5
6
7
| $ screen -r
screen -r
There is a screen on:
27386.pts-0.rahulchandna (11/02/2013 16:42:21) (Attached)
There is no screen to be resumed.
|
- start a new screen terminal
- exit from a new screen terminal, while it is still running
1
| $ press control + a followed by control +d
|
- View all screen processes id
1
2
3
4
5
6
| $ screen -r
There are several suitable screens on:
27694.pts-0.rahulchandna (11/02/2013 16:49:21) (Detached)
27386.pts-0.rahulchandna (11/02/2013 16:42:21) (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
|
- connect to a particular screen using id from above