Bash

SSH to Multiple Hosts in Parallel

admin by @admin ADMIN
1d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Run the same command on a fleet of hosts. Three patterns: serial loop (simplest), GNU parallel (fastest), pssh (purpose-built).
Bash
Raw
HOSTS=(web1 web2 web3 db1)

# Serial — slow but easy to reason about
for h in "${HOSTS[@]}"; do
    echo "─── $h ───"
    ssh -n "$h" uptime
done

# Parallel with xargs (limit to 8 concurrent)
printf '%s\n' "${HOSTS[@]}" | xargs -P 8 -I{} ssh -n -o ConnectTimeout=5 {} uptime

# GNU parallel (cleaner output, must be installed)
parallel -j 8 ssh {} uptime ::: "${HOSTS[@]}"

# pssh — built specifically for this
pssh -h hosts.txt -i 'uptime'
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.