Session Sharing and Collaboration
Tmux supports multiple clients connecting to the same session. This enables pair programming, supervised access, and live incident debugging.
Core Idea
Any Unix user who can access the tmux socket can attach to a session. This is the simplest remote collaboration tool available on a server.
Same User — Multiple Terminals
The simplest case: you attach the same session from two terminal windows.
# terminal 1 — attach
tmux attach -t work
# terminal 2 — attach to the same session
tmux attach -t work
Both windows show the same tmux session. Input in one is reflected in the other.
Use cases:
- Large monitor + laptop screen simultaneously
- Presenting your terminal to another person via screen share
Different Users — Socket Sharing
To share a session with another Unix user, you need to share the tmux socket.
Method 1: Shared Socket File
# User A — create session with a shared socket
tmux -S /tmp/shared-tmux new -s collab
# Set socket permissions
chmod 777 /tmp/shared-tmux
# User B — attach via same socket
tmux -S /tmp/shared-tmux attach -t collab
warning
chmod 777 on the socket is broad. For production use, create a shared Unix group and set socket permissions to g+rw instead.
Method 2: Group-Based Permission (Safer)
# Create a shared group (as root)
groupadd tmux-shared
usermod -aG tmux-shared alice
usermod -aG tmux-shared bob
# User alice — create socket in a shared group path
tmux -S /run/tmux-shared/collab new -s work
chgrp tmux-shared /run/tmux-shared/collab
chmod g+rw /run/tmux-shared/collab
# User bob — attach
tmux -S /run/tmux-shared/collab attach -t work
Read-Only Collaboration
You can attach in read-only mode so the observer can see but not type:
tmux attach -t work -r
Use cases:
- Junior engineer watching a senior engineer debug live
- Demo session where the observer should not accidentally type
Pair Programming Session Setup
pair-session.sh
#!/bin/bash
SOCKET="/tmp/pair-$(date +%s)"
SESSION="pair"
# Create shared session on a unique socket
tmux -S "$SOCKET" new -s "$SESSION" -d
chmod 777 "$SOCKET"
echo "Session ready."
echo "Partner attaches with:"
echo " tmux -S $SOCKET attach -t $SESSION"
Checking Attached Clients
# List clients attached to sessions
tmux list-clients
Output:
/dev/pts/0: work [220x50 xterm-256color] (utf8)
/dev/pts/1: work [220x50 xterm-256color] (utf8)
Detach a Specific Client
# Detach a specific client by device
tmux detach-client -t /dev/pts/1
Security Considerations
| Risk | Mitigation |
|---|---|
| Socket world-writable | Use group permissions instead of 777 |
| Unauthorized access | Keep shared sockets in restricted directories |
| Logging shared sessions | Use script or audit logs for sensitive sessions |
| Forgetting to clean up | Delete socket file after collaboration ends |