Saturday, April 20, 2024
HomeA-Z CommandsHow To Use Screen Command on Linux To Manage Terminals

How To Use Screen Command on Linux To Manage Terminals

The screen command is a terminal command that can play the role of the multiplexer. In other words, you can run screen commands on your terminal shell to keep applications live in the background, run packages as a daemon, and keep a session (SSH) live for a long time, even if you’re disconnected.

The screen command is helpful and handy for all system administrators and Linux power users. This multiplexer-type tool is powerful enough to run shell commands between a server, console, and other machines.

Screen Command on Linux

For those who love to run multiple terminal shell commands simultaneously in multiple windows, the screen command would be perfect for them. In Linux, the command itself handles processes so that the system doesn’t get slower and keeps your sessions live.

Through the screen command, you can attach, detach, and reattach the window as per your requirement on Linux. In this post, we will see how to install and use the screen command on Linux.

1. Install Screen Command on Linux

The first step to getting started with the screen command would be to have the tool on your Linux system. The installation of the screen command is easy for all major Linux distributions. Since the tool is very popular among most users, it is already available on the official Linux repository. We can install it through the dedicated package installer command on Linux.

Please execute the following command on your terminal shell according to your distribution. Please make sure that you have an active internet connection and that you have the root privilege on your system.

Install Screen Tool on Debian/Ubuntu System

$ sudo apt-get install screen
screen install on Linux

Get the Screen Tool on Red Hat and Fedora Linux

$ sudo yum install screen

Install Screen on Arch Linux

$ sudo pacman -S screen

Get the Screen Tool on SuSE Linux

$ sudo zypper install screen

Once the installation finishes, you may now run the tool on your system by simply writing screen on the shell.

$ screen

2. Display Screen Command Parameter

So far, we have got the notion of the Screen command, but we haven’t got any real practice of the Screen command. Before we try to do some tweaking through the Screen command, we must know the basic commands and the idea of how to use them.

For starters, you can execute the following command to get the fundamental commands of the Screen tool. Please note that all the commands have to be executed without the quotes.

“Ctrl-A” and “?”

To view the help manual for the Screen tool, you can press the space bar or press the Enter button.

3. Detach the Terminal Session with Screen

Detaching the running terminal or shell sessions is one of the most used features of the Screen command on Linux. It also allows the users to detach and restore the windows without losing any data or sessions.

If you need to run longer sessions over SSH for downloading packages over the web, you can use the Screen command on the SSH. On an SSH connection, you can just type ‘screen’ to run the screen tool.

$ screen

4. Re-attach the Terminal Session with Screen

Once you detach the screen on your Linux through the Screen command, you can re-attach it on your system through the following screen command with an r flag.

$ screen -r
Screen Command

To see all the sessions that are running on the Screen command, you will need to run the following ls command.

$ screen -ls

If you know the exact name of your screen session and the port, you can restore or re-attach that specific session through the following screen command on Linux.

$ screen -r 7849

5. Using Multiple Screen Terminal Windows

The screen command also allows the users to run multiple screens at a time on the system and switch between the windows. To attach, re-attach, and detach the running sessions on an embedded screen. You can also close the first running screen window and then browse the next screen, but the previous screen won’t be closed.

To switch between the running and previous screens on the nested or the embedded screen, you can use the following key combinations on your keyboard.

Swap between screens: “Ctrl-A” and “n“
Go to the prior screen:“Ctrl-A” and “p“
To create a new screen: “Ctrl-A” and “c“

6. Enable Screen Logging in Linux

Sometimes, on a screen command session or an SSH session, you might need to log or record the sessions for future reference. You can press the following key combination to record the session.

Log or Redcord the session: “Ctrl-A” and “H“

Please note that you must press the capital H with the Ctrl key to log the session; pressing the small h would only take a screenshot. All the screen logs will be stored inside the home directory on your Linux filesystem.

Once you reach the point where you do not need to record anymore, you may now stop the recording. Please press the same “Ctrl-A” and “H“ key combinations again on the screen session to stop logging the screen.

The method mentioned above will keep a record of your screen logs; however, you can just execute the following screen command on your Linux shell to log the current screen session.

$ screen -L

7. Lock the Linux Terminal Screen

To make your SSH shell and other screen commands secure, you can execute the following key combinations to lock the screen.

Press the “Ctrl-A” and “x”

To add a secure password on your screen command, you can set a new password. The password will be saved on the “$HOME/.screenrc” file. To set the password, you will need to edit the file, find the following syntax, and add the password.

password crypt_password

You can execute the following make password command.

$ mkpasswd Ubutupit123

8. Leaving Screen Terminal Session

This would be the command that we will need to exit the Screen command sessions. There are two ways to exit or quit the screen command that you can execute. First, you can use the following key combination to detach the screen.

Ctrl-A” and “d”

The second option would be the manual method to quit the terminal shell by clicking the cross button or pressing the Ctrl-A and K to kill the screen command on Linux.


The screen command is a very powerful yet easy-to-handle command on Linux. In the entire post, I have described the method of installing and using the Screen command on a Linux system.

If you find this post useful and informative, please share it with your friends and the Linux community. You can also write down your opinions about this post in the comment section. 

Please share it with your friends and the Linux community if you find this post useful and informative. You can also write down your opinions regarding this post in the comment section.

Mehedi Hasan
Mehedi Hasan
Mehedi Hasan is a passionate enthusiast for technology. He admires all things tech and loves to help others understand the fundamentals of Linux, servers, networking, and computer security in an understandable way without overwhelming beginners. His articles are carefully crafted with this goal in mind - making complex topics more accessible.


Please enter your comment!
Please enter your name here

You May Like It!

Trending Now