This article describes how to use the screen program.
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.
To start screen, log in to your A2 Hosting account using SSH, and then type the following command:
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:
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.
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.
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:
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 http://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:
Log out of SSH, and then log back in. Screen should now work.