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.

What is screen?

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.

Installing screen

On most Linux distributions, screen is available via the default package manager.

For Debian/Ubuntu:

sudo apt update
sudo apt install screen

For CentOS/RHEL:

sudo yum install screen

For Fedora:

sudo dnf install screen

Basic Usage

Starting a Screen Session

screen

This command opens a new screen session. You’ll see a welcome message and a terminal prompt.

Naming Your Session

screen -S mysession

Use -S to assign a name to your session for easy reference later.

Detaching and Reattaching

Detach From a Session

Inside the screen session, press:

Ctrl + A, then D

This detaches the session and leaves it running in the background.

List Active Sessions

screen -ls

This displays a list of current screen sessions:

There are screens on:
12345.mysession (Detached)

Reattach to a Session

screen -r mysession

Or use the session ID:

screen -r 12345

Working with Multiple Windows

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.

Logging and Output

To log output from a screen session:

  1. Start or enter your screen session.

  2. Enable logging:

    Ctrl + A, then H

    This creates a file called screenlog.0 in the current directory.

Closing a Session

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:

exit

in each.

Advanced Tips

  • 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.

Conclusion

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!