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:
For CentOS/RHEL:
For Fedora:
Basic Usage
Starting a Screen Session
This command opens a new screen session. You’ll see a welcome message and a terminal prompt.
Naming Your Session
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:
This detaches the session and leaves it running in the background.
List Active Sessions
This displays a list of current screen sessions:
Reattach to a Session
Or use the session ID:
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:
Start or enter your screen session.
Enable logging:
This creates a file called
screenlog.0in 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:
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!


