Using tmux to share a terminal

I just ran a short seminar where I used tmux to share a terminal with other users. It was quite effective. This posting describes how to set it up.

You need a shared ssh account that you’re willing to allow the other participants to log into. I set up a new account with a default password, and opened up the firewall ports to allow ssh in. By the way, I doubt this is very secure, so this may not be suitable for seminars with untrusted users.

In your standard account (not the shared one), run tmux like this:

tmux -S /tmp/shared

/tmp/shared is the shared tmux socket that the shared account users will connect to. It is created with restricted permissions, so you have to also do this:

chmod 777 /tmp/shared

Now I changed the shared account’s shell (in /etc/passwd) to point to a script called /home/shared/run-tmux which contains:

#!/bin/sh -
exec /usr/bin/tmux -S /tmp/shared attach -r

When the shared user logs in, they will immediately be attached, read-only (-r), to the shared tmux session. I also had to make this script owned by root, unwritable, and had to give it an SELinux label so that sshd could run it:

chown root.root /home/shared/run-tmux
chmod 0555 /home/shared/run-tmux
chcon system_u:object_r:bin_t:s0 /home/shared/run-tmux

Seminar users now ssh to the shared account, and see the shared screen:

The only peculiarity of tmux is that it resizes the window area to the size of the smallest client, even for read-only clients. Thus if any client makes their windows smaller, you see this:

There is probably some tmux configuration to avoid this, but I couldn’t immediately see it.

8 Comments

Filed under Uncategorized

8 responses to “Using tmux to share a terminal

  1. You probably want to use setfacl rather than chmod 777 to do this more securely.

  2. I’ve been meaning to try tmux out, thanks.
    Here are my related notes with screen:
    http://www.pixelbeat.org/docs/screen/

    • rich

      I started with screen, but the issue I had was that if any user disconnected, it closed the whole session!

      • Alon

        I just tried tmux (screen user) and it did the same:

        terminal A:
        tmux create-session

        terminal B:
        tmux attach
        exit (^D)

        session closed! (both A and B).

        Other then that tmux looks nice, and seems to have a comparable number of options, with better command line at first glance (git sub-command syntax)

  3. tmux is cool. I’ve posted my tmux conf here(modified version from the interwebs)
    https://github.com/kashyapc/config-files/blob/master/tmux.conf

  4. q

    @Alon that’s not disconnecting, that’s exiting the shell; it’s normal for the session to close, because the only process running in it has terminated. Disconnecting without exiting the shell would be “detaching” (C-b d) and should not affect the session.

  5. B.

    Richard, this is execellent again. I was just about to script and test something on my own, then big G showed me probably missed some older post from you 🙂

    You’re doing a really goog blog, at least for anyone interessted in virtualization and “shelling”. Thanks for that.

    BTW: I am quite sorry i didn’t get in touch with you again on sunday at DevConf.cz, so you could have told me this right away 🙂

  6. Pingback: » Linux: Is there a way to mirror USB outputs?

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.