Run one command on many servers or switches at once, safely
Short answer. To run a command on multiple servers from a shell, pssh -h hosts.txt -i 'uptime' or an Ansible ad hoc command does it in one line. To type into several open sessions at once, tmux has synchronize-panes and ClusterSSH opens a window per host. Whatever the tool, the safe order is the same: fix the host list, run on one host, read its output, then widen, and leave production for last.
Sending one command to forty machines takes the same effort as sending it to one, and so does sending a typo. This article covers the tools that do it, what goes wrong with them, a routine that keeps a mistake small, and how MyXterm builds that routine into the app.
Two different jobs with one name
Run it on all of them
can mean two things, and the tools for each are different.
- Run on a list. You give a tool a command and a list of hosts. It connects to each one, runs the command and brings back a result per host. Nothing is interactive.
- Broadcast typing. You open a session to each host and one keyboard types into all of them. You see every screen live, and every keystroke lands everywhere, including the wrong ones.
Use the first for anything that changes state. Keep the second for interactive work on a few similar machines that you can watch at the same time.
Command-line tools
pssh (Parallel SSH)
pssh provides parallel versions of the OpenSSH tools [1]. It reads hosts from a file and runs one command on each:
pssh -h hosts.txt -l admin -i 'uptime'
-h names the host file, -l the default user, and -i prints each host's output as it completes. -p caps the number of concurrent connections, -t sets a timeout, and -o saves each host's output to a file in a folder [1]. It works best with keys or an agent; -A asks for one password and passes it to every connection.
Ansible ad hoc commands
An ad hoc command automates a single task on one or more hosts without writing a playbook [2]. The hosts come from your inventory:
ansible web -m ansible.builtin.shell -a 'uptime' -f 10
Without -m Ansible uses its command module, which doesn't support pipes and redirects; the shell module does. It runs on five hosts at a time unless you raise that with -f. Check mode (-C) makes no changes on the remote systems [2].
tmux synchronize-panes
If you already have one pane per host in a tmux window, one window option duplicates your input to all of them [3]:
tmux set-option -w synchronize-panes on
tmux set-option -w synchronize-panes off
The second line matters as much as the first. Nothing in the panes themselves shows that the option is on, and the next thing you type goes everywhere.
ClusterSSH
cssh server1 server2 server3 opens an xterm to every host plus a small administration console. Text typed into the console is replicated to all windows, and you can still type into one window on its own [4]. It is built on Perl/Tk and xterm, so it needs an X display.
What goes wrong
- The typo goes everywhere. There is no first host to notice the mistake on.
- Nobody reads forty outputs. A wall of text hides the three hosts that answered differently.
- The list is wider than you think. A group or a file pattern quietly includes a production host, or a host someone added this morning.
- Prompts. A command that asks a question (a sudo password, a
[confirm]
on a switch) hangs, or takes the next line of input as its answer. - Half-done runs. The connection drops halfway through and you no longer know which hosts got the command.
- Exit codes that say nothing. On network devices a command can
succeed
and still print% Invalid input. - Broadcast left on. You finish, switch to another task, and keep typing into every pane.
A routine that keeps mistakes small
- Start read-only. Run the
showorstatusversion of the command first. It tests the list, the sign-in and the syntax for free. - Fix the list. Write the targets down before you start, so that an edit to the inventory halfway through can't change who gets the command.
- One canary. Run on a single host that is not production. Read its output yourself, not only its exit code.
- Widen in steps, and stop at the first failure instead of pushing through.
- Production last, with its own canary.
- Keep a record: the exact command, the hosts, and what each one answered.
- Have a way back for changes that can cut you off. The guide for network engineers shows confirmed commits and scheduled reloads.
With pssh that means a one-line host file first and the full file second. With Ansible, a narrower host pattern limits the run to one host. With broadcast typing there is no canary at all, which is the reason to keep it away from changes.
How MyXterm does it
MyXterm is a free, open-source (Apache-2.0) connection manager and terminal for macOS, Linux and Windows. v0.1.0 is the first stable release. macOS builds are signed and notarized; Windows and Linux builds are not code-signed yet.
It has both tools, and the routine above is built into the first one [5].
Run command on hosts
Select saved SSH sessions or a folder in the sidebar and choose Tools, Run command on hosts…
partial AUTO-002. A tab opens with one command field and these steps:
- Preview. Every host is listed with its environment,
user@host:port, its jump hosts and the one way it will sign in. Hosts that can't take part are listed as excluded, each with the reason. Two sessions that point at the same host run once. The command is shown with hidden characters made visible. - Canary first. One host runs before the others. You read its result and press Continue, which is disabled if the canary failed and for the first second after the result appears.
- Production last, and never by accident. Hosts that aren't production run before production ones. Every PROD host, and every host with no environment set, needs its own tick; above ten you type their count. Production gets its own canary.
- No stray keys. Enter and Space never start a run, and a held shortcut advances only one step.
- No prompts. Each host gets its own connection with no terminal and no forwarding. A host whose key isn't trusted yet fails instead of asking. The run stops after the first failure by default, and always after three failed sign-ins in a row.
- Results you can read. Hosts are grouped by identical state, exit code and output, so the odd ones stand out. A result says whether a command never started, was sent with an unknown outcome, or finished. You can export it as TSV or JSON.
- A record. Before anything is sent, MyXterm writes an audit file readable only by you: the targets, the command, and then per host the outcome, the address it connected to and the host key fingerprint. If the file can't be written, a run that includes production is blocked.
Multi-input
For interactive work, multi-input (⌘⌥I on macOS, Ctrl+Shift+I on Windows and Linux) sends what you type to every pane of a tab partial AUTO-003. Every pane that takes part gets an outline and a MULTI-INPUT badge, so the mode is never invisible. PROD panes are left out until you include them with a second click, and a paste with a line break that is mirrored into a PROD pane still asks in that pane partial TERM-009.
What MyXterm doesn't do yet
- SSH on the built-in engine only. Run command on hosts leaves out sessions that use the system OpenSSH engine, hosts that would need a typed sign-in, and Telnet and serial sessions. They appear in the Preview as excluded.
- One line. Multi-line commands are not supported, and neither are waves: it runs the canary, then the rest.
- Switches and routers. The command is sent without a terminal, which suits servers. Network devices differ in how they handle that, and we have not tested it against real ones.
- Multi-input stays inside one tab. Choosing panes one by one, or sessions across tabs, is planned AUTO-108. It was checked by hand with three panes on a lab VM.
- Not checked on screen in the three themes, and there is no record of a hand test on Windows or Linux yet.
- No scripting. If you need loops, conditions or templates, that is Ansible's job, not a terminal's.
Download MyXterm Features and status
FAQ
How do I run a command on multiple servers over SSH?
From a shell, pssh reads a host file and runs the command on every host in parallel, and an Ansible ad hoc command does the same from an inventory. Both work best with key or agent sign-in. Run on one host first and read its output before you widen.
How do I send a command to multiple sessions at once?
In tmux, turn on synchronize-panes for the window and your typing goes to every pane. ClusterSSH does the same with one window per host. In MyXterm, multi-input types into every pane of a tab and leaves production panes out until you include them.
What is a canary host?
One host that gets the command before the others. You read its result, and only then let the rest run. It turns a mistake on forty hosts into a mistake on one.
Can MyXterm run a command on switches and routers?
Run command on hosts works over SSH on the built-in engine and sends the command without a terminal. That suits servers. Network devices differ in how they handle it, and we have not tested it on real ones. Telnet and serial sessions are left out.
Sources
All read on 4 December 2026. Projects change their options; check the source before you rely on it. MyXterm statuses are from features.toml on the same day; partial
means it works in the app but does not meet its full acceptance criteria yet.
- pssh (Parallel SSH Tools), README and the
psshmanual page: github.com/lilydjwg/pssh, man/man1/pssh.1 - Ansible, Introduction to ad hoc commands: docs.ansible.com/ansible/latest/command_guide/intro_adhoc.html
- tmux manual page (
synchronize-panes,set-option): man.openbsd.org/tmux - ClusterSSH repository and README: github.com/duncs/clusterssh
- MyXterm: the
Run command on hosts
and multi-input entries in CHANGELOG.md, the rules in crates/runon/src/lib.rs, and AUTO-002 and AUTO-003 in features.toml
Last updated