If you’ve ever had a long-running task in a Linux terminal interrupted by a lost SSH session or a closed terminal window, you know how frustrating it can be. Luckily, Linux servers provides a powerful utility called screen that allows you to run terminal sessions in the background, detach from them, and reconnect later — even after disconnection.
In this guide, we’ll walk you through the basics of using screen, from installation to common commands.
screen is a terminal multiplexer that lets you create multiple terminal sessions inside one window. You can detach from a session, leave it running in the background, and reattach later — making it perfect for remote work or running persistent processes.
On most Linux distributions, screen is available via the default package manager.
This command opens a new screen session. You’ll see a welcome message and a terminal prompt.
Use -S to assign a name to your session for easy reference later.
Inside the screen session, press:
This detaches the session and leaves it running in the background.
This displays a list of current screen sessions:
Or use the session ID:
Inside a screen session, you can create multiple terminal windows.
Create new window: Ctrl + A, then C
Switch to next window: Ctrl + A, then N
Switch to previous window: Ctrl + A, then P
List all windows: Ctrl + A, then ” (double quote)
Each window runs its own shell, and all continue running in the background if you detach.
To log output from a screen session:
Start or enter your screen session.
Enable logging:
This creates a file called screenlog.0
in the current directory.
To exit a session, simply type exit
in the screen terminal. This terminates the shell and closes the session.
If you have multiple windows, you must exit all of them or close the entire session by typing:
in each.
Scrollback: Ctrl + A, then Esc lets you enter copy/scrollback mode.
Sharing a session: Multiple users can connect to the same session by using multiuser mode.
Custom configs: Modify ~/.screenrc for personal shortcuts and preferences.
screen is a must-have tool for any Linux user managing long-running tasks or working remotely via SSH. Its ability to keep processes alive and accessible makes it invaluable for developers, sysadmins, and enthusiasts alike.
Explore man screen for even more capabilities — and start working smarter in your terminal!