Terminal Multiplexers

What Multiplexers Solve

Core problems addressed
# 1. Session persistence -- survive disconnects
ssh server1
tmux new -s deploy                       # start multiplexer
./long-running-deploy.sh                 # safe if SSH drops
# Ctrl-b d                              # detach
# SSH reconnect later
tmux attach -t deploy                    # reconnect to same session

# 2. Multiple terminals in one connection
# Single SSH connection → multiple shells via panes/windows

# 3. Pair programming
# Two users attach to same tmux session
tmux -S /tmp/pair new -s collab
chmod 777 /tmp/pair
# Other user: tmux -S /tmp/pair attach -t collab

Architecture

Client-server model
Terminal Emulator
  └── tmux client (or screen client)
        └── tmux server (runs in background)
              ├── Session: "infra"
              │   ├── Window 0: "monitoring"
              │   │   ├── Pane 0: htop
              │   │   └── Pane 1: journalctl -f
              │   └── Window 1: "config"
              │       └── Pane 0: nvim
              └── Session: "dev"
                  └── Window 0: "editor"
                      └── Pane 0: nvim

Workflow Patterns

Infrastructure session layout
# Create standard infra layout
tmux new-session -d -s infra -n monitor
tmux send-keys -t infra:monitor "htop" Enter
tmux new-window -t infra -n logs
tmux send-keys -t infra:logs "journalctl -f" Enter
tmux new-window -t infra -n ssh
tmux split-window -h -t infra:ssh
tmux send-keys -t infra:ssh.0 "ssh vault-01" Enter
tmux send-keys -t infra:ssh.1 "ssh ise-01" Enter
tmux select-window -t infra:monitor
tmux attach -t infra
Addressing scheme
# tmux target syntax: session:window.pane
tmux send-keys -t infra:0.1 "ls" Enter   # session infra, window 0, pane 1
tmux select-pane -t dev:editor.0          # session dev, window "editor", pane 0
tmux select-window -t infra:2             # window 2 in session infra

Multiplexer vs Terminal Tabs

Feature Multiplexer (tmux) Terminal tabs

Session persist

Yes (survives SSH drop)

No (dies with terminal)

Remote access

Attach from any client

Local only

Scriptable layout

Full CLI automation

Limited

Pair programming

Multi-attach

No

Resource usage

Lightweight (server process)

Per-tab process

Scrollback

Independent per pane

Per-tab

When to use

Remote servers, persistent work

Quick local tasks

Zellij (Modern Alternative)

Zellij basics
# Start
zellij                                   # default session
zellij -s infra                          # named session

# Layout from YAML
zellij --layout ~/.config/zellij/layouts/dev.kdl

# Default keybindings use modes (like vim)
# Alt+n      new pane
# Alt+h/l    switch pane
# Alt+[/]    switch tab
# Ctrl+p     pane mode
# Ctrl+t     tab mode
# Ctrl+s     scroll mode
# Ctrl+o     session mode → d to detach

# List and attach
zellij list-sessions
zellij attach infra