Share Linux Terminal Session

How to Share Linux Terminal Session With Others

Often Linux users start a session and work alone by themselves in Linux. By default, every session is meant for one and only one user. But sometimes you may need to share Linux terminal session with others so as to show them your work. In this article, we will learn how to share Linux terminal session with others. You can easily do this using tmux utility, which allows you to detach, move your sessions to another machine and resume it.


How to Share Linux Terminal Session With Others

We will look at two use cases – one where multiple users log in using same user account, and the other where multiple users log in using different user accounts.


Screen Sharing Using Single Account

Here are the steps to setup a simple terminal session sharing for one account.

Using Screen

Open terminal and run the following screen command to create a session named abc.

$ screen -S abc

Then open another terminal, on same or different machine, and run the following command to attach to that session. Please note, you need to login using the same account that was used to create the above session.

$ screen -x abc

Using tmux

You can also share session using tmux utility. Open terminal and run the following command to start the session abc using tmux.

$ tmux new-session -s abc

Open a new terminal on same of different machine, using the same user account and run the following command to attach to the above session.

$ tmux attach-session -t abc


Screen Sharing using Different Accounts

When people login using different accounts, they need additional steps in order to be able to share sessions.

Using tmux

First of all, we need to set permissions on tmux socket so that both users can read & write to it. The two users need to be a part of the same user group. Open terminal and run the following command to create a new session named shared running on shareds socket.

$ tmux -S /tmp/shareds new -s shared

Then we use chgrp to add shareds socket to group named joint. Please note, other users who are present in this group will also be able to access the session.

$ chgrp joint /tmp/shareds

Open another terminal and run the following command to attach to the shared session.

$ tmux -S /tmp/shareds attach -t shared

Using Screen

Sharing session using screen is a little complicated, in this case. You need to set SUID to screen command and remove group write access from /var/run/screen. Then use screen’s ACL to grant permission to second user.

Here is the command to set SUID and remove write access from /var/run/screen.

$ sudo chmod u+s /usr/bin/screen
$ sudo chmod 755 /var/run/screen

Next, run the following commands to start a session named abc and add user user2 to the session.

$ screen -S abc
$ ^A:multiuser on
$ ^A:acladd user2

The second user can attach to the first user’s session using the following command.

$ screen -x user1/abc

Please note

If you directly exit the shell during session sharing, it will end the session for all users. So you need to first detach the session and then exit your terminal. In tmux you can do that with ^B-d and in screen that is ^A-d.

In this article, we have learnt how to share session in Linux using tmux and screen utilities.

Also read:

How to Use WhoIs command in Linux
How to Extract & Copy Files from ISO Image in Linux
Tools to Scan Linux for Viruses & Malware
How to Run Multiple PHP Versions in Apache
How to Run Multiple PHP Versions in NGINX

Leave a Reply

Your email address will not be published. Required fields are marked *