Skip to content

Instantly share code, notes, and snippets.

Created October 31, 2012 03:46
Star You must be signed in to star a gist
What would you like to do?
Start multiple synchronized SSH connections with Tmux
# ssh-multi
# D.Kovalov
# Based on
# a script to ssh multiple servers over multiple tmux panes
starttmux() {
if [ -z "$HOSTS" ]; then
echo -n "Please provide of list of hosts separated by spaces [ENTER]: "
read HOSTS
local hosts=( $HOSTS )
tmux new-window "ssh ${hosts[0]}"
unset hosts[0];
for i in "${hosts[@]}"; do
tmux split-window -h "ssh $i"
tmux select-layout tiled > /dev/null
tmux select-pane -t 0
tmux set-window-option synchronize-panes on > /dev/null
Copy link

@greymd xpanes! - Thank you! I've been looking for exactly this off and on for two years.

Copy link

WMcKibbin commented Mar 29, 2019

# Assume session is 0
tmux attach-session -t 0
WINDOW=$(tmux display-message -p "#I")

for arg in $*; do
    if [[ $arg != *"%"* ]]; then
        if [[ $FIRST_ARG == "" ]]; then
            tmux send-keys "ssh $arg" Enter
            tmux split-window "ssh $arg"
        tmux select-layout tiled
tmux set-window-option synchronize-panes on

This is how my old co-worker accomplished this, figured I'd drop in this thread not as a replacement but an alternate option.

Copy link

#!/usr/bin/env bash
instead of of hardcoded shebang

Copy link

Kimeg commented Jan 11, 2021

Thank you, sir. I found your code very useful for setting environments across multiple servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment