How to use screen

This article describes how to use the screen program.

When to use Linux screen

Have you ever been working at the command line over a SSH connection and the connection drops? Alternatively, have you ever wanted to run multiple programs from the command line without opening a separate SSH connection to run each command?

The screen program can handle these scenarios and more. You can use screen to maintain an open terminal session, even if the connection drops. Likewise, you can open multiple text windows and run multiple commands from within a single SSH session.

How to use screen

To start screen, log in to your A2 Hosting account using SSH, and then type the following command:

screen
If you receive an error message, please see the Troubleshooting section below.

You can obtain a list of active screen sessions by typing the following command:

screen -ls

You should see output similar to the following text:

There is a screen on:
        231102.pts-2.sr10       (Attached)
1 Socket in /home/username/.screen.

This output shows that you currently have one attached screen session. You can type commands and work in the shell as you normally would.

  • To open a new text window, press Ctrl-a and then type c. A new window opens where you can type commands.
  • To move between windows, press Ctrl-a and then type n. This command takes you to the next window.
  • To close a window or screen session, type exit.
  • You can view online help for the screen application by pressing Ctrl-a and then ?. You can also use the following command:
    man screen

You may also want to create a customized status bar to make it easier to see which window you are currently using. To do this, create a ~/.screenrc file. For example, to display the server hostname and window name at the bottom of the screen, add the following line to the ~/.screenrc file:

hardstatus alwayslastline "[%H] %w "
Please do not leave idle screen sessions open for long periods of time. Also, make sure you do not violate the A2 Hosting Terms of Service. For example, do not leave CPU-intensive processes running for a long time. For more information, please see the A2 Hosting Terms of Service.

Troubleshooting Linux screen

By default, some types of accounts (such as shared hosting accounts) may not be able to use the screen program. For screen to work, the bash shell must be enabled on your account. To determine your current shell environment, log in to your account using SSH and type the following command:

echo $SHELL

If your shell is set to jailshell, the screen program will not work. If you want to use screen, open a ticket with the A2 Hosting Guru Crew at https://my.a2hosting.com and request that the bash shell be enabled for your account.

However, even if the bash shell is enabled for your account, you may receive an error similar to the following message when you try to start screen:

Directory '/var/run/screen' must have mode 775.

If you receive this error message, type the following command:

mkdir ~/.screen && chmod 700 ~/.screen

Then add the following line to your ~/.bashrc file:

export SCREENDIR=$HOME/.screen

Log out of SSH, and then log back in. Screen should now work.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.