Using the screen program
Learn how to use the screen program in Linux to manage terminal sessions, run multiple commands, and maintain sessions even if your connection drops.

This article explains how to use screen with step-by-step instructions and relevant code snippets.

When to use Linux screen
Have you ever lost your SSH connection while working at the command line? Or wanted to run multiple commands without opening separate SSH sessions?

The screen program handles these situations. It lets you maintain open terminal sessions if the connection drops and allows you to open multiple text windows to run commands within a single SSH session.

How to use screen
To start screen, log in to your ruachost.com account via SSH and run:

screen
Note
If you encounter an error, see the troubleshooting section below.

To list active screen sessions, run:

screen -ls

You may see output like:

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

This shows that one screen session is attached. You can type commands as usual.

  • To open a new window, press Ctrl-a then c.

  • To switch between windows, press Ctrl-a then n.

  • To close a window or session, type exit.

  • To view help within screen, press Ctrl-a then ?, or run:

man screen

You can also create a customized status bar by adding a ~/.screenrc file. For example, to display the server hostname and window name at the bottom:

hardstatus alwayslastline "[%H] %w "

Important
Do not leave idle screen sessions open for long periods or run CPU-intensive processes for extended times, in accordance with our Terms of Service.

Troubleshooting screen
Some accounts, such as shared hosting, may not support screen. The bash shell must be enabled. To check your shell, run:

echo $SHELL

If it shows jailshell, screen will not work. To enable bash, submit a support ticket at https://ruachost.com.

Even with bash enabled, you may encounter:

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

To fix this, run:

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

Then add this line to your ~/.bashrc file:

export SCREENDIR=$HOME/.screen

Log out and back in via SSH, and screen should work properly.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Powered by WHMCompleteSolution