Today we are going to introduce you a handy application called “Screen”.
We all know about SSH and it’s limits, normally when we need to have 2 terminal windows we have to create a second SSH, and if the connection breaks during the SSH tunnel, you’ve lost your progress.
This is where “Screen” comes in, a useful tool to use on SSH connections.
Also, another great feature of Screen is that it doesn’t kill the process if your SSH connection is dropped. So you may use it for background processes or running scripts like cPanel installation which takes a long time.
We are assuming that you have root permission, otherwise, you may start commands with “sudo”.
Install Screen
On CentOS 6 or CentOS 7
yum install screen
On Debian 6 / 8 and Ubuntu 14 / 16
apt-get install screen
That’s it, you’ve installed Screen Successfully.
Working with Screen
Let’s get to know Screen a little more.
With below command, you can create one or more sessions in your current SSH terminal:
screen
Now let’s see some of the most important short-keys of Screen:
Ctrl a c : Create a new Screen session within a Screen session
Ctrl a n : Switches to the next Screen session (if you use more than one)
Ctrl a p : Switches to the previous Screen session (if you use more than one)
Ctrl a d : Detaches a screen session (without killing the processes in it)
Ctrl a k : stopping screen and kill the session (you will get a message before termination)
To close a Screen session where all tasks are finished you can type:
exit
You always can see a list of your running Screen Sessions by the command below:
screen -ls
Output example:
And to reconnect to one of these sessions, type:
screen -r 15155.pts-0.test-lab
Locking your Screen session
If you need to step away from your computer for a minute, you can lock your Screen session using the short-key below: (This will require a password to access the session again)
Ctrl a x
Getting Alerts
If you are waiting for output from a long-running program, you can use the short-key below to look for activity. the Screen will then flash an alert at the bottom of the page when output is registered on that screen.
Ctrl a m
Screen Logging
Screen will keep appending data to the file through multiple sessions. if something goes wrong, you can look back through your log:
You can active your Screen logging mechanism by:
Ctrl+a H
Your log file is always in your current Screen path you can open it by the command below:
less screenlog.0
You can always learn more about Screen running the command below:
man screen
You can find out more information about Screen and releases in its offcial website.
What if here is no internet connection, how do I install screen, which are the binaries needed?
Cheers!
I need to help me how to install screen
Did you read the article? It tells you exactly how to install screen.