How do I use the Screen command in CentOS

In CentOS, a terminal multiplexer is known as Screen or GNU Screen. Using this multiplexer, you can create a screen session and then open as many virtual terminals or windows as you want within that session. In case if you are offline, your system processes operating in a screen session will continue to run in the background, even if the session is not visible.

 

The screen utility is quite useful when working with numerous programs from a command-line interface or terminal shell. It also offers you the facility to detach and attach terminal sessions and share your sessions with other users.

In this post, you will learn how I use the Screen command in the CentOS system. So let’s start!

How to install Screen in CentOS

Screen utility is not included in the CentOS 8 distribution. So, if you are using CentOS 8 and want to install “Screen“, then firstly, you have to enable the “EPEL repository” on your system:

sudo yum install epel-release

Now, write out the below-given command for installing Screen on your CentOS system:

sudo yum install screen

How to use Screen in CentOS

If you want to utilize the Screen command, then type “screen” in your CentOS terminal:

screen

Now, you will see the following command-line interface of a Screen session:

To check out the parameters or commands of the Screen utility, Press “CTRL+A” and then “?”. This action will provide you the following information about the Screen:

You can press “Space” to view the next page or “Esc” to return from this window:

How to detach a Screen session in CentOS

We are currently working on the “screen 0” Screen session. To detach the “screen 0” session, we will press “CTRL+A” and then “d”:

How to reattach a Screen session in CentOS

Using your CentOS terminal, if you want to reattach any Screen session, then execute the command given below:

screen -r

From the output, you can see that multiple screen sessions are running on our CentOS system:

How to find Screen session ID in CentOS

If multiple Screen sessions are operating on your CentOS system, you have to specify the session ID in the session reattach command. In the screen command, add the “-ls” combination option to list out the Screen session with their specific session IDs:

screen -ls

From the retrieved output, note down the ID of the required Screen session:

In the “screen” command, adding the “-r” option forces the Screen command to reattach a Screen session. Also, you have to specify session ID in this command:

screen -r 4154

Now, the screen session “screen 0” is reattached:

How to switch between Screen sessions in CentOS

We have mentioned earlier that more than one Screen session may be operating simultaneously on your CentOS system. Want to switch between those Screen sessions? Press “CTRL+a” and “n” to move to the next Screen and “CTRL+a” and “p” to switch back to the previous Screen.

For instance, currently, we are using the “screen 1” session. To move back to the “screen 0”, we will press “CTRL+p” and “n”:

You can see that the previous Screen is “screen 0”, in which we switched back in:

Again, by pressing “CTRL+a” and “n”, we will move to the next screen session:

How to enable screen logging in CentOS

Screen command also allows you to record every command you have executed in your Screen session. It creates a separate log file for this purpose. To utilize this feature of the Screen command, activate the screen logging by executing the below-given command in your current Screen session:

screen -L

Here, the “-L” option is added to activate the Screen logging function:

How to lock a Screen session in CentOS

If you want to lock your Screen session, then press “CTRL+a” and “x”:

Now, your current Screen session “screen 2” is locked after pressing the keys mentioned above. To unlock it, enter your CentOS system password:

How to add a password to Screen session in CentOS

For certain security reasons, you may want to apply a password to your Screen session. This operation will ask the user to input the specified password whenever he/she wants to reattach that session.

Firstly, to utilize the functionality of adding a password to a Screen session, you have to generate a hash password. We will execute the below-given “mkpasswd” command for generating a hash password for the “linuxhint”:

sudo mkpasswd linuxhint

From the terminal output, note down the hash password:

Now, open up the “.screenrc” file in your “nano” editor and add the hash password to it:

sudo nano .screenrc

This “.screenrc” file is the configuration file of the GNU Screen:

Add the hash password, and press “CTRL+O” to save the “.screenrc” file content:

password 97hjeZPp+

Now, reattach the Screen session having the session ID “4154”:

screen -r 4154

After switching back to the specified Screen session, press “CTRL+a” and “x” to lock this session:

Enter the hash password you have added in the “.screenrc” file to unlock this Screen session:

How to leave a Screen session in CentOS

There exist two ways through which you can leave your current Screen session. Either press “CTRL+a” and “d” to detach the session or “CTRL+a” and “k” to terminate the currently running Screen session:

Posted on: April 17, 2024, by :  | 109 views
https://serang.ut.ac.id/css/css/slot88/ https://tinjut.bagkeu.dikdasmen.kemdikbud.go.id/slot-maxwin/ https://dpm.polinema.ac.id/slot-gacor/ https://akademik.ft.unm.ac.id/slot-dana/ https://ppdb.probolinggokab.go.id/slot-5000/ https://bkad.sulselprov.go.id/assets/ https://ojs.balidwipa.ac.id/docs/slot-gacor/ http://korpri.pekalongankab.go.id/api/slot-gacor/ https://elang.umpp.ac.id/foto/farmasi/-/asset/ http://rsud-kelet.jatengprov.go.id/wp-content/-/asset/ https://kusdhianto-fe.staff.ugm.ac.id/slot88/ http://ppdb.probolinggokab.go.id/judi-bola/ https://bapenda.labuhanbatukab.go.id/racikan-sbobet/ http://rsud-kelet.jatengprov.go.id/wp-content/-/data/ https://agenda.riau.go.id/-/judi-bola/ https://balapan.padang.go.id/sbobet88/ http://jdih.wakatobikab.go.id/sbobet88/ http://kph.menlhk.go.id/sbobet88/ https://bkad.sulselprov.go.id/data/ https://dpm.polinema.ac.id/slot-gacor/ https://dinkes.jemberkab.go.id/storage/attachments/