URI: 
       Managing 5 Servers at Once with tmux
       
       Published on : 2026-03-02 13:30
       
       I manage five machines every day: tiny, lenovo1, lenovo2, lenovo3 
       and my nas. More info about my cluster can be found at this link:
       
   DIR  🗄 Cluster information
       
       Opening five terminals and SSHing manually works - but it's 
       repetitive, easy to mess up and something I don't want to do every 
       time.
       
       So I automated the entire thing with a small shell script 
       that builds a complete tmux workspace for me.
       
       The Idea
       ‾‾‾‾‾‾‾‾
       
       One command. Five panes. Five active SSH sessions. Synchronized 
       input enabled. Instant cluster control.
       
       Screenshot & Video
       ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
       
   IMG  Managing 5 servers at once with tmux [screenshot]
   BIN  Managing 5 servers at once with tmux [video]
       
       The Script
       ‾‾‾‾‾‾‾‾‾‾
       
       Below is the exact script I use, with comments explaining each 
       step.
       
           #!/usr/bin/env bash
           
           # Create a tmux session named "Manage Cluster"
           # -A  : attach if it already exists
           # -s  : session name
           # -d  : start detached (in the background)
           tmux new-session -As "Manage Cluster" -d
           
           # Split the current window vertically 5 times
           # This creates additional panes stacked vertically
           tmux split-window -v
           tmux split-window -v
           tmux split-window -v
           tmux split-window -v
           tmux split-window -v
           
           # Arrange all panes in evenly sized vertical layout
           tmux select-layout even-vertical
           
           # Select pane 1 and SSH into tiny
           tmux select-pane -t 1
           tmux send-keys 'ssh tiny' 'C-m'   # C-m presses Enter
           
           # Select pane 2 and SSH into lenovo1
           tmux select-pane -t 2
           tmux send-keys 'ssh lenovo1' 'C-m'
           
           # Select pane 3 and SSH into lenovo2
           tmux select-pane -t 3
           tmux send-keys 'ssh lenovo2' 'C-m'
           
           # Select pane 4 and SSH into lenovo3
           tmux select-pane -t 4
           tmux send-keys 'ssh lenovo3' 'C-m'
           
           # Select pane 5 and SSH into nas
           tmux select-pane -t 5
           tmux send-keys 'ssh nas' 'C-m'
           
           # Return focus to the first pane
           tmux select-pane -t 1
           
           # Enable synchronized panes
           # All keystrokes will now be sent to every pane simultaneously
           tmux set-window-option synchronize-panes
           
           # Attach to the session using 256-color mode
           # -2 forces 256-color support
           # -d detaches other attached clients
           tmux -2 attach-session -d
       
       
       What Happens When I Run It
       ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
       
       The moment I execute the script:
       
        * a tmux session is created (or reused if already running);
        * the window splits into five evenly sized vertical panes;
        * each pane automatically SSHs into its assigned machine;
        * synchronized input is enabled;
        * I am attached to the session;
        * no manual setup;
        * no tab juggling;
        * no repeated SSH commands.
       
       Why Synchronized Panes Matter
       ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
       
       With synchronization enabled, I can:
       
        * run updates on all machines at once;
        * restart services everywhere;
        * check disk usage across the cluster;
        * run maintenance commands in parallel.
       
       It turns five separate servers into something that feels like a 
       single distributed shell.
       
       Enabling/disabling synchronized panes
       ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
       
           unbind "S"
           bind S set-window-option synchronize-panes
       
       With this bind I can easily CTRL + b -> Shift + s to enable or 
       disable synchronized panes in tmux.
       
       Of course, this is powerful - and dangerous.
       ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
       
       If I type:
       
           rm -rf /tmp/something
       
       It runs everywhere. Deliberate typing only and makes me think 
       twice before pressing ENTER and mess something up.
       
       Why Five Panes?
       ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
       
       Five is the sweet spot for my screen. Everything fits. 
       All machines are visible. Nothing is hidden.
       
       Nah, I'm joking !!! My cluster is composed of 5 nodes but the 
       script is easy to modify if I add or delete a node!
       
       The Result
       ‾‾‾‾‾‾‾‾‾‾
       
       What used to be five terminals and constant context switching is 
       now:
       
        * one command;
        * one window;
        * five live systems;
        * total and instant control.
       
       If you manage multiple servers daily, scripting your tmux layout 
       like this is worth the few minutes it takes to build.
       
       It turns infrastructure management into something that feels 
       almost orchestral.
       
   DIR  Back to my phlog