parallel-ssh(1)
β¨ NAME β¨
okay bestie, welcome to parallel-ssh(1) β she lives in the General Commands Manual section and she is literally the parallel ssh program. that's it, that's the vibe. π
πΈ SYNOPSIS πΈ
parallel-ssh [-vAiIP] [-h hosts_file] [-H [user@]host[:port]] [-g
pattern] [-l user] [-p par] [-o outdir] [-e errdir] [-t timeout] [-O
options] [-x args] [-X arg] command ...
parallel-ssh -I [-vAiIP] [-h hosts_file] [-H [user@]host[:port]] [-g
pattern] [-l user] [-p par] [-o outdir] [-e errdir] [-t timeout] [-O
options] [-x args] [-X arg] [command ...]
π¦ DESCRIPTION π¦
so like. parallel-ssh is a program that runs ssh in parallel across a whole bunch of hosts. no cap, it's giving "I refuse to log into 100 machines one by one" energy. π
the features it brings to the function:
- sending input to all of the processes
- passing a password to
ssh - saving output to files
- timing out
okay now here's the tea about environment variables. the PSSH_NODENUM, PSSH_NUMNODES, and PSSH_HOST environment variables are sent to the remote host.
PSSH_NODENUMgets a unique number for eachsshconnection, starting with0and counting up. π’PSSH_NUMNODESgets assigned the total number of node being used.PSSH_HOSTgets assigned the name of the host as specified in the hosts list.
β οΈ ngl this part matters: sshd drops environment variables by default, so sshd_config on the remote host must include the line:
AcceptEnv PSSH_NODENUM PSSH_NUMNODES PSSH_HOST
π OPTIONS π
-h host_file--hosts host_fileβ Read hosts from the given host_file. Lines in the host file are of the form[user@]host[:port]and can include blank lines and comments (lines beginning with"#"). If multiple host files are given (the-hoption is used more than once), thenparallel-sshbehaves as though these files were concatenated together. If a host is specified multiple times, thenparallel-sshwill connect the given number of times. ποΈ-H[user@]host[:port]--host[user@]host[:port]-H"[user@]host[:port] [ [user@]host[:port ] ... ]"--host"[user@]host[:port] [ [user@]host[:port ] ... ]"β Add the given host strings to the list of hosts. This option may be given multiple times, and may be used in conjunction with the-hoption. π«Ά-g pattern--host-glob patternβ Filter hosts with glob pattern pattern. This uses the same syntax as shell globs. Make sure to quote the pattern to prevent shell from expanding it. Examples are"*web*"and"company_*". π-l user--user userβ Use the given username as the default for any host entries that don't specifically specify a user.-p parallelism--par parallelismβ Use the given number as the maximum number of concurrent connections. πβοΈπ¨-t timeout--timeout timeoutβ Make connections time out after the given number of seconds. With a value of0,parallel-sshwill not timeout any connections. β°-o outdir--outdir outdirβ Save standard output to files in the given directory. Filenames are of the form[user@]host[:port][.num]where the user and port are only included for hosts that explicitly specify them. The number is a counter that is incremented each time for hosts that are specified more than once.-e errdir--errdir errdirβ Save standard error to files in the given directory. Filenames are of the same form as with the-ooption.-x args--extra-args argsβ Passes extra SSH command-line arguments (see thessh(1)man page for more information about SSH arguments). This option may be specified multiple times. The arguments are processed to split on whitespace, protect text within quotes, and escape with backslashes. To pass arguments without such processing, use the-Xoption instead. β¨-X arg--extra-arg argβ Passes a single SSH command-line argument (see thessh(1)man page for more information about SSH arguments). Unlike the-xoption, no processing is performed on the argument, including word splitting. To pass multiple command-line arguments, use the option once for each argument.-O options--options optionsβ SSH options in the format used in the SSH configuration file (see thessh_config(5)man page for more information). This option may be specified multiple times.-A--askpassβ Prompt for a password and pass it tossh. The password may be used for either to unlock a key or for password authentication. The password is transferred in a fairly secure manner (e.g., it will not show up in argument lists).
π¨ however, be aware that a root user on your system could potentially intercept the password.
-i--inlineβ Display standard output and standard error as each host completes. π--inline-stdoutβ Display standard output (but not standard error) as each host completes.-v--verboseβ Include error messages fromsshwith the-iand-eoptions.-I--send-inputβ Read input and send to eachsshprocess. Sincesshallows a command script to be sent on standard input, the-Ioption may be used in lieu of the command argument. π₯-P--printβ Display output as it arrives. This option is of limited usefulness because output from different hosts are interleaved. π
π EXAMPLES π
Connect to host1 and host2, and print "hello, world" from each:
parallel-ssh -i -H "host1 host2" echo "hello, world"
Print "hello, world" from each host specified in the file hosts.txt:
parallel-ssh -i -h hosts.txt echo "hello, world"
Run a command as root with a prompt for the root password:
parallel-ssh -i -h hosts.txt -A -l root echo hi
Run a long command without timing out:
parallel-ssh -i -h hosts.txt -t 0 sleep 10000
If the file hosts.txt has a large number of entries, say 100, then the parallelism option may also be set to 100 to ensure that the commands are run concurrently:
parallel-ssh -i -h hosts.txt -p 100 -t 0 sleep 10000
Run a command without checking or saving host keys:
parallel-ssh -i -H host1 -H host2 -x "-O StrictHostKeyChecking=no
-O UserKnownHostsFile=/dev/null -O
GlobalKnownHostsFile=/dev/null" echo hi
Print the node number for each connection (this will print 0, 1, and 2):
parallel-ssh -i -H host1 -H host1 -H host2 'echo $PSSH_NODENUM'
π TIPS π
If you have a set of hosts that you connect to frequently with specific options, it may be helpful to create an alias such as:
alias parallel-ssh_servers="parallel-ssh -h
/path/to/server_list.txt -l root -A"
note that when an ssh command is terminated, it does not kill remote processes (OpenSSH bug #396 has been open since 2002 π). One workaround is to instruct ssh to allocate a pseudo-terminal, which makes it behave more like a normal interactive ssh session. To do this, use parallel-ssh's "-x" option to pass "-tt" to ssh. For example:
parallel-ssh -i -x "-tt" -h hosts.txt -t 10 sleep 1000
will ensure that all of the sleep commands will terminate (with SIGHUP) after the 10 second timeout.
By default, ssh uses full buffering for non-interactive commands. Line buffering may be preferable to full buffering if you intend to look at the files in an output directory as a command is running. To switch ssh to use line buffering, use its "-tt" option (which allocates a pseudo-terminal) using the "-x" option in parallel-ssh.
The ssh_config file can include an arbitrary number of Host sections. Each host entry specifies ssh options which apply only to the given host. Host definitions can even behave like aliases if the HostName option is included. This ssh feature, in combination with parallel-ssh host files, provides a tremendous amount of flexibility. π§
π EXIT STATUS π
The exit status codes from parallel-ssh are as follows:
0β Success β¨1β Miscellaneous error2β Syntax or usage error3β At least one process was killed by a signal or timed out.4β All processes completed, but at least onesshprocess reported an error (exit status255).5β There were nossherrors, but at least one remote command had a non-zero exit status.
π AUTHORS π
Written by Brent N. Chun <bnc@theether.org> and Andrew McNabb <amcnabb@mcnabbs.org>.
https://github.com/lilydjwg/parallel-ssh
π SEE ALSO π
ssh(1), ssh_config(5), parallel-scp(1), parallel-rsync(1), parallel-slurp(1), parallel-nuke(1),
and that's the whole page, bestie!! this one's dated January 24, 2012 and it comes to you from the General Commands Manual, living under the name parallel-ssh(1). go forth and ssh in parallel, you absolute icon. πβ¨π¦
π¦ where this page comes from
- debian bookworm: pssh 2.3.4-2 Β· BSD-3-Clause
- debian trixie: pssh 2.3.5-2 Β· BSD-3-Clause
- ubuntu jammy: pssh 2.3.4-2 Β· BSD-3-Clause
- ubuntu noble: pssh 2.3.5-2 Β· BSD-3-Clause
- ubuntu questing: pssh 2.3.5-2
- ubuntu resolute: pssh 2.3.6-1 Β· BSD-3-Clause
- ubuntu stonking: pssh 2.3.6-1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms