Linux Screen provides users an option to open several separate terminal instances within a single terminal window manager. Screen also includes an enhanced command line, giving you extra features and functionality over a standard command line.
This tutorial will show you how to install and use Screen on a Linux system.
- A user account with sudo privileges
- Access to a command line / terminal window (Ctrl+Alt+t/Ctrl+Alt+F2)
How to Install Screen on Linux
If you’re running a recent version of Linux, like Ubuntu 20.04 or CentOS 8, you probably already have Screen installed.
To verity if Screen is installed, check the version with the command:
Installing Screen on CentOS
To install Screen on Red Hat / CentOS, enter the command:
yum install screen
Installing Screen on Debian or Ubuntu
To install Screen on Debian/Ubuntu, enter the following:
sudo apt install screen
How to Use Linux Screen Examples
Below you will find the most common Screen commands with examples on how to use them.
Starting Linux Screen
To launch Linux Screen and start a screen session, run the command:
The initial launch begins with a brief licensing agreement displayed on the screen. Press Space to continue to the next page.
Press Space again to open a new screen session.
The system drops out to a command line that looks just like a regular terminal window.
The manage screen shells, use Screen keystrokes (in most cases, Ctrl + a, followed by another key). To see a list of available commands press the keys Ctrl + a, followed by ?.
While working in Screen, it is recommended to name each session. This helps you keep track of instances if you have multiple screen sessions running.
To launch and name a new session, use the command:
screen -S session_name
For instance, to create a session named upgrade, you run:
screen -S upgrade
Working with Linux Screen
Once you launch Screen, the application creates a window with a shell inside of the screen session. Add, switch, and manage windows using command keystrokes.
The most commonly used keystrokes include:
- Ctrl + a and c – Open a new screen window.
- Ctrl + a and " – List all open windows.
- Ctrl + a and 0 – Switch to window 0 (or any other numbered window).
- Ctrl + a and A – Rename the current window.
- Ctrl + a and S - Split the screen horizontally, with the current window on top.
- Ctrl + a and | - Split the screen vertically, with the current window on the left.
- Ctrl + a and tab – Switch focus between areas of the split screen.
- Ctrl + a and Ctrl + a – Switch between current and previous windows.
- Ctrl + a and n – Switch to the next window.
- Ctrl + a and p – Switch to the previous window.
- Ctrl + a and Q – Quit all other windows except the current one..
- Ctrl + a and X – Lock the current window.
- Ctrl + a and H – Create a running log of the session.
- Ctrl + a and M – Monitor a window for output (a notification pops up when that window has activity).
- Ctrl + a and _ - Watch a window for absence of output (such as when a file finishes downloading or a compiler finishes).
Detaching and Reattaching Screen
To detach from screen and leave the window running in the background, use the keystroke:
Ctrl + a and d
The command leaves the process working in Screen and exits the interface. It is the equivalent of minimizing a window in a graphical operating system.
To reattach to a running screen session, use:
If you only have one Screen instance, you don’t need to enter the session ID. If you have more than one, you’ll need to specify which session ID you want to reconnect to.
Each screen session has a different ID and you can see the session ID list with the command
Once you have the ID, add it to the
screen -r command:
screen -r sessionID
For example, to restore screen 3361.upgrade, run:
screen -r 3361.upgrade
Locking and Adding Passwords to Screen
To lock the screen, use the shortcut:
Ctrl + a and x
The default lock screen mechanism asks for your Linux password to unlock the screen.
Additionally, Screen allows you to protect a session with its own password. Each time you attempt to reattach to the screen, you need to provide the set password.
To create a password-protected screen, run the command:
your_passowrd with a strong password of your choice.
The next time you try to reattach to the password-protected screen, you have to provide two passwords to enter – your Linux password, followed by your Screen password.
Like many Linux applications, Screen uses a customizable configuration file. Find the system-wide configuration file at /etc/screenrc. The user’s configuration file is located at ~/.screenrc.
To edit, open the file:
sudo nano /etc/screenrc
Most of the settings can be toggled by removing the comment (#) sign at the beginning of the line.
This tutorial showed you how to install Linux screen as well as the basic commands for using it.
Once you have mastered using the screen interface, you can navigate through multiple terminals, multitask and work more efficiently.