In my work I support Linux servers, which means focusing on the command line; that starts with the SSH command.
(I’ve previously blogged about personalising the Linux command line, and different SSH keys - this post continues this theme.)
Parallel SSH (install with sudo apt install pssh) is faster to run commands against multiple remote hosts from the command line, while using SSH under the hood. The output is a host name header followed by the command output, for instance running the date command on SERVER1 and SERVER2 with parallel SSH would result in:
[1] 09:14:18 [SUCCESS] person@SERVER1.local
Mon 18 May 18 2026 09:14:18 AEST
[2] 09:14:18 [SUCCESS] person@SERVER2.local
Mon 18 May 18 2026 09:14:18 AEST
You can see from the results I connected as person, and the command was run on both servers at once.
While parallel SSH isn’t going to beat a full-blown automation tool, it’s great for a small amount of servers, or a small number of changes - and it doesn’t require afore-mentioned tool. Nothing needs to be installed on the remote hosts.
Anatomy of a parallel-ssh command
Breaking down the above command to connect to two remote hosts, and run a command on each: parallel-ssh -i -H 'person@SERVER1.local person@SERVER2.local' -A -x '-i ~/.ssh/key_file_name' -- date:
- interactive (e.g. run command):
-i - list of hosts follows:
-H - passes SSH key in extra options to SSH command set the key file name:
-x - if key has passphrase (it should!),
parallel-sshprompts once for the passphrase (using the same key for all the hosts):-A - command to run is after double dashes
- fails if you haven’t accepted server fingerprint (so, need to connect first time manually)
- if username is the same for all connections (like
person), can specify once with-l:parallel-ssh -i -l person -H 'SERVER1.local SERVER2.local' -A -x '-i ~/.ssh/key_file_name ' -- w -
can specify file instead of list of hosts (
-H) with-h linux_hosts.txt(you can use any name you like, I chose “linux_hosts.txt”)- newline separated
- can contain comments starting with hash
- in list of hosts, can also specify user to connect with per connection, or not e.g.
person2@SERVER1.local SERVER2.local
- I haven’t needed it yet, but appears difficult to be prompted for
sudopassword when running a command that requiressudoon multiple remote hosts…though possibly a start at https://groups.google.com/g/parallel-ssh/c/hN3qf5zQ7gI/m/KdmGe8woCgAJ
Full documentation is at https://manpages.ubuntu.com/manpages/jammy/man1/parallel-ssh.1.html.
Here’s some of the ways I’ve used parallel SSH, given a file linux_hosts.txt with a list of remote hosts, separated by newlines:
# what version of OS is running
parallel-ssh -i -l person -h ~/linux_hosts.txt -A -x '-i ~/.ssh/key_file_name' 'hostnamectl | grep Operating'
# what SSH keys do I have deployed
parallel-ssh -i -l person -h ~/linux_hosts.txt -A -x '-i ~/.ssh/key_file_name' 'cat ~/.ssh/authorized_keys'
# getting a hash of a file, to compare to see if it's the same file
# e.g. with config files such as .inputrc or .bashrc
parallel-ssh -i -l person -h ~/linux_hosts.txt -A -x '-i ~/.ssh/key_file_name' 'sha256sum ~/.ssh/authorized_keys'
# it's possible to get a hash of a whole directory too! Claude tells me the command is something like
parallel-ssh -i -l person -h ~/linux_hosts.txt -A -x '-i ~/.ssh/key_file_name' "find ~ -maxdepth 1 -type f -printf '%f|%s|%TY-%Tm-%Td %TH:%TM:%TS|%m|%u|%g\n' | sort | sha256sum"
There’s also parallel SCP, which you can use to copy files from your computer to multiple hosts at the same time:
parallel-scp -l person -h ~/linux_hosts.txt -A -x '-i ~/.ssh/key_file_name' local.file remote.file
(And parallel-slurp for the reverse.)
References:
- https://www.techrepublic.com/article/how-to-run-remote-commands-on-multiple-linux-servers-with-parallel-ssh/
- https://www.interserver.net/tips/kb/parallel-command-execution-on-multiple-servers-using-parallel-ssh/
- https://anastarsha.com/use-parallel-ssh-to-run-commands-on-multiple-devices-at-the-same-time/