guest@6admin.io:~$

Screen: a terminal multiplexer

Screen is a terminal multiplexer that, like a window manager, allows multiple text-mode programs to run simultaneously from a single interface, typically a local or remote terminal via SSH (no, nothing to do with nohup, which I mainly use for certain scripts with wget).

Installation

On Gentoo:

logout@lifthrasir ~ $ su -c "emerge app-misc/screen"
Password:
[...]

On Debian:

logout@helghardhr:~$ sudo apt-get install screen
Password for user logout:
[...]

Let’s practice

We will create a screen session to take control of a switch:

logout@lifthrasir ~ $ screen -S elivghar

Here we have created a screen session named elivghar. We can verify with the screen -ls command:

logout@lifthrasir ~ $ screen -ls
There are screens on:
        15115.irc       (Detached)
        15098.elivghar  (Attached)
2 Sockets in /tmp/screens/S-logout.

Two sessions: one detached (irc), one attached (elivghar, the one we just created). Detaching is done with Ctrl+A D and reconnecting with screen -r elivghar. The session survives logout: if SSH cuts, the process continues running in the screen session and you find it at the next login.

The essential shortcuts:

  • Ctrl+A C : new window
  • Ctrl+A N : next window
  • Ctrl+A P : previous window
  • Ctrl+A D : detach session
  • Ctrl+A K : kill session
  • Ctrl+A " : window list

This is the tool that has survived every SSH session since 1987 and has made the fortune of sysadmins who never want to lose a long-running process because SSH dropped.