Sharing remote terminal session between two users with Tmux
Posted on January 2nd, 2011 in tmux, unix | 6 Comments »
I’ve yet to write my “Wonders of Tmux” entry but always have small tidbits to give in the meantime.
Sometimes sharing your whole desktop via Skype, Teamviewer, or some other screen-sharing system is overkill, at the very least harder to read and control remotely. Sharing a terminal session between two (or more) users is great for pair programming (especially if both users are vi or emacs users) or for one user to educate, walk-through, or troubleshoot something with another remote user – also great for showing how Tmux works! One can even split the screen in half and be SSH’d into multiple machines together!
There’s three ways that users can share a terminal session together. The first way requires a little more work from the person sharing their tmux session, the second and third require either sudo rights or being able to su to the other user’s account.
Similar to SSH, when you create a tmux session, it creates a temporary socket in the /tmp directory with the tmux user owning the file. This makes it unaccessible by other users.
Allow another user access to your tmux session:
# specify the name of your tmux socket with -S when creating it tmux -S /tmp/pair # chmod to allow other users to access it chmod 777 /tmp/pair # now the other user can connect with tmux -S /tmp/pair attach
Sudo your way into another users tmux session
# Have the user create a tmux session # ls -al /tmp to see which tmux session is owned by the user you want to share sessions with then # in the following example tmux-502 is the tmux socket folder of the example user sudo tmux -S tmux-502/delfault attach
su your way into the session
su username # need user's password or sudo tmux attach
6 Responses
Note that this doesn’t allow them just access to the tmux session you happen to be looking at, but also allows them to create new sessions that you might not be watching and execute arbitrary commands there. If you’re doing this, make sure you trust the other person with full, unsupervised access to your account on that host. Note that this includes current session information; e.g., if you have your ssh-agent forwarded to that host, the other user can ssh as you into any other host allowed by those keys.
[...] and the status of machine set -g status-right ‘#[fg=yellow]#(uptime | cut -d “,” -f 2-)’ http://readystate4.com/2011/01/02/sharing-remote-terminal-session-between-two-users-with-tmux/ Allow another user access to your tmux session: # specify the name of your tmux socket with -S [...]
I just wanted to say thank you for sharing that practical tip
[...] TMUX CONFIG no wrap in vim sharing tmux sessions [...]
Instead of su, you can run:
sudo -u username tmux attach
[...] http://readystate4.com/2011/01/02/sharing-remote-terminal-session-between-two-users-with-tmux/ [...]