Bash: Sharing a terminal screen among users with tmux

Desktop screen sharing is ubiquitous, but there is still a lot of value in sharing a live terminal screen with another set of users that can not only view, but also have the ability to copy-paste and even provide input.

The tmux utility can create a session using a shared socket.  To start a tmux session:

# socket to use
sharedSocket=/tmp/$(whoami)_tmux_shared
echo "Tell the other user to connect to: $sharedSocket"

# create tmux session with this socket
tmux -S $sharedSocket new-session -s $(whoami)_tmux_shared

This initiating user should now give the socket the proper permissions to grant to others to view.

chmod 777 /tmp/$(whoami)_tmux_shared

And from the perspective of a user wanting to view this live terminal session

# originating user and socket
originalUser="foo"
sharedSocket=/tmp/${originalUser}_tmux_shared

# open share session, use "CTRL-b d" to detach
# the '-r' forces read-only
tmux -S $sharedSocket attach-session -t ${originalUser}_tmux_shared -r

Here are links to my supporting github scripts tmux-new-shared-session.sh and tmux-view-shared-session.sh

REFERENCES

tmux man page

lukaszwrobel.pl, tmux splitting windows and session sharing, and alt-arrow key bindings

codeburst.io, binding for resize-panel

NOTES

Ctrl-b ” for horizontal split

Ctrl-b % for vertical split

Ctrl-b [ for scrolling with page up/down

create ~/.tmux.conf for alt-arrow bindings and repeat resize-panel

# alt-arrow to move among panes
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# vim like resizing
bind -r 'h' resize-pane -L 5
bind -r 'l' resize-pane -R 5
bind -r 'k' resize-pane -U 5
bind -r 'j' resize-pane -D 5