You are browsing a read-only backup copy of Wikitech. The live site can be found at

Collaborative tmux sessions

From Wikitech-static
Jump to navigation Jump to search

Sometimes you want another pair of eyes when troubleshooting or working in production machines. The tools screen and tmux are being used to create collaborative terminal sessions.


Create tmux session:

tmux new -s session_name

Join tmux session:

tmux attach -t session_name

You can use the -r flag for read-only connections:

tmux attach -rt session_name

Create sessions with fixed size

It could happen that different terminal sizes are used (old hardware, mobile, big fonts for better readability). By default, tmux will fall back to the window size of the smallest connected client. The behavior can be changed by setting the the window-size option. Possible options are largest, smallest, manual, latest. When creating a new session, this option can be set to manual to prevent unwanted changes of the window size:

tmux new -s session_name \; setw window-size manual \; attach

Join tmux session is the same:

tmux attach -t session_name

Share session between users

It is possible to share tmux session between different users.

Share session using sockets

By default tmux will create a socket in /tmp/tmux-<user_id>/default. It is also possible to explicitly use a different socket using the -S option:

tmux -S /path/to/socket new -s session_name

To connect to this session, grant the user which wants to connect read and write access to the socket and then use:

tmux -S /path/to/socket attach

This method is useful when you don't want to use root (see below). Use this method with caution if you are in a shared environment with different user privileges. Users may use this to escalate privileges.

"Share" session using root/sudo

It is also possible to create a tmux session as root and let others join by using sudo/root:

sudo -i tmux new -s session_name

Join the tmux session:

sudo -i tmux attach -t session_name

Keep in mind that you are using the root user here. So for read-only operations and debugging you may want to use your personal user and share the session using sockets or su back to a user with less privileges.