Sharing *NIX Screens

Sharing Terminal Sessions With Tmux And Screen

tmux and GNU Screen are well-known utilities which allow multiplexing of virtual consoles. Using either, it is possible to start a session, detach, move to a different machine and resume the session in uninterrupted progress. It's also possible to use these tools to share a single session between more than one user at the same time.

 

Basic Sharing with a Single Account

If an account is held jointly between two or more users, then the sharing of the terminal console is very simple. Neither tmux nor screen require anything out of the ordinary for basic sharing between a single account logged in multiple times. Basic sharing is very easy if you are both logged in as the same user.

Basic Sharing With screen

There are only two steps:

  1. In one terminal create a new session for screen, where foobar is the name of your screen session:

    screen -S foobar

  2. In the other terminal, attach to that session:

    screen -x foobar

Basic sharing with tmux

There are only two steps:
  1. In the first terminal, start tmux where shared is the session name:

    tmux new-session -s shared

  2. In the second terminal attach to the shared session:

    tmux new-session -t shared

Sharing Between Two Different Accounts

Sharing between two different accounts requires some additional steps to grant the privileges necessary for one account to access another's session. In some cases, it will require help from the system administrator to prepare the setup.

Sharing between two different accounts with tmux

For different users, permissions must be set on the tmux socket so that both users can read and write it.  There is only one prerequisite: that there be a group in common between the two users.  If such a group does not exist it will be necessary to create one.

  1. In the first terminal, start tmux where shared is the session name and shareds is the name of the socket:

    tmux -S /tmp/shareds new -s shared

  2. Then chgrp the socket to a group that both users share in common. In this example, joint is the group that both users share. If there are other users in the group, then they also have access.

    chgrp joint /tmp/shareds

  3. In the second terminal attach using that socket and session:

    tmux -S /tmp/shareds attach -t shared

    1. Alternately, the second user could connect to the shared screen as read-only:

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

Sharing between two different accounts with screen

If you are logged in as two different users:

  1. screen must be set SUID and it is necessary to remove group write access from /var/run/screen. The safety of using SUID in this context is something to consider.

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

  2. Use screen's ACLs to grant permission to the second user:

    1. In the first user's terminal, start screen as in the basic sharing above, where foobar is the name of the screen session. Then turn on multiuser mode and add user2 to the ACL, where user2 is the second account to be sharing the session:

      screen -S foobar

      ^A:multiuser on

      ^A:acladd user2

    2. The session can be made read-only for the second user by entering the following ACL change:

      ^A:aclchg user2 -w "#?"

  3. In the other terminal, attach to the first user's session.

    screen -x user1/foobar

Cautions

Take care when exiting. If you just exit the shell, it will end the terminal session for all parties. If you instead detach the session then the other user can continue working uninterrupted.

  • In tmux:

    ^B-d

  • In screen:

    ^A-d