tutorials bash

Collaborate in the shell with screen (multiuser)

Screen is a neat little program that allows you to use multiple virtual terminals in a single session on Unix/Linux and Mac. However, it does more than just that. It can also allow you to share your current session on a machine with another user - allowing you to collaboratively hack away at a problem in real time.

Issue commands to screen using Ctrl-A followed by one of the command instructions, or a further key combination.

While you can use this method to connect as many people to a given screen session as you like, only one person can be typing in a given window at once. That person is described as having the 'writelock' on the window. By default these are set to 'auto', meaning the first user to start typing gets the writelock and keeps it until they leave the window.

A user's writelock can be removed manually by using the command writelock off. In contrast the command writelock on means that user will keep the writelock even after leaving the window.

Before getting started there is an important permissions setup to perform. In order to share screens between two separate users on a system screen must be set suid root. Doing this has a slight security risk (if there are bugs in screen that allow compromise by a logged in user) but is neccessary to ensure that both users have the permissions to see each other's sessions.

To set up the permissions open a terminal and enter:

python
sudo chmod +s /usr/bin/screen  # Make screen suid root
sudo chmod 755 /var/run/screen # Make the screen dir more open

Note that if you want to share a screen between two sessions of the same user on a system you can skip this step entirely. This is useful for example if you have a shared login on a system.

Now that's out of the way we can create the screen session as normal. So first start screen to create a named session - here called test

python
screen -S test

Once in the screen session we need to tell screen to allow the screen sharing to commence. Commands to screen are performed using Ctrl-A key combination followed by a command (or another key combination). So do the following;

python
CTRL-A
:multiuser on

CTRL-A
:acladd <username>

Replacing <username> with the name of the user you are granting screen sharing access to.

You can save yourself some time by putting these commands in the .screenrc configuration file.

You can also control permissions more closely for example :aclchg <username> +rx will give <username> read-only access to the screen.

Finally ask your guest to connect to your server via ssh and enter the following to access your screen:

python
screen -x <your-username>/test

The screen follows the general format of <your-username>/<your-screename> meaning you can have and share multiple screen sessions at once if you so wish!

Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt6
More info Get the book

Downloadable ebook (PDF, ePub) & Complete Source code

To support developers in [[ countryRegion ]] I give a [[ localizedDiscount[couponCode] ]]% discount on all books and courses.

[[ activeDiscount.description ]] I'm giving a [[ activeDiscount.discount ]]% discount on all books and courses.