pssh(1)
πΈ pssh(1) β General Commands Manual πΈ
okay so bestie, you know how you've got like a million servers and you're supposed to ssh into each one individually like some kind of Victorian orphan? π no. absolutely not. that's pssh erasure and we don't do that here. this is pssh, the parallel ssh program, and she is iconic, she is efficient, she is your main character. section 1 of the manual, general commands, let's GO π
β¨ NAME β¨
pssh β parallel ssh program
π¦ SYNOPSIS π¦
pssh [-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 ...
pssh -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 what pssh does is it runs ssh in parallel across a whole bunch of hosts at once. that's it, that's the vibe. π«Ά and she's not just one-trick either β she's got features like sending input to all of the processes, passing a password to ssh, saving output to files, and timing out. lowkey a full package.
now the environment variable tea, because this part matters:
the PSSH_NODENUM, PSSH_NUMNODES, PSSH_HOST environment variables are sent to the remote host.
PSSH_NODENUMgets assigned 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.
β οΈ but listen βsshddrops environment variables by default, sosshd_configon the remote host must include the line:
AcceptEnv PSSH_NODENUM PSSH_NUMNODES PSSH_HOST
no cap, if that line isn't there your env vars are just gonna evaporate into the void. π
π 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), thenpsshbehaves as though these files were concatenated together. and if a host is specified multiple times, thenpsshwill connect the given number of times. yes, on purpose. β¨-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. besties working together fr fr π«Ά-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_*". π₯ quote it, queen, or the shell will eat it before pssh even sees it.-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,psshwill not timeout any connections. zero means infinite patience, she's chill like that. π§-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. one arg, one flag, no notes. π-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. π so like, it's good but not bulletproof, ok?-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. yeah it's chaos, we said what we said. π
π EXAMPLES π
connect to host1 and host2, and print "hello, world" from each:
pssh -i -H "host1 host2" echo "hello, world"
print "hello, world" from each host specified in the file hosts.txt:
pssh -i -h hosts.txt echo "hello, world"
run a command as root with a prompt for the root password:
pssh -i -h hosts.txt -A -l root echo hi
run a long command without timing out:
pssh -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:
pssh -i -h hosts.txt -p 100 -t 0 sleep 10000
run a command without checking or saving host keys:
pssh -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):
pssh -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 pssh_servers="pssh -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 pssh's "-x" option to pass "-tt" to ssh. for example:
pssh -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. iconic workaround behavior honestly. π
by default, ssh uses full buffering for non-interactive commands. line buffering may be preferrable 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 pssh.
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 pssh host files, provides a tremendous amount of flexibility. like, the flexibility is giving β¨ chef's kiss β¨.
π EXIT STATUS π
the exit status codes from pssh are as follows:
0β Success1β 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/pssh
π«Ά SEE ALSO π«Ά
ssh(1), ssh_config(5), pscp(1), prsync(1), pslurp(1), pnuke(1),
and that's the whole page bestie, mwah π this one shipped out January 24, 2012, so it's lowkey vintage but highkey still slaying. go run some parallel commands, you've got this, periodt. πΈβ¨
π¦ where this page comes from
- epel 10: pssh 2.3.5-8.el10_0 Β· LicenseRef-Callaway-BSD
- epel 9: pssh 2.3.4-1.el9 Β· BSD
- fedora 43: pssh 2.3.5-13.fc43 Β· LicenseRef-Callaway-BSD
- fedora 43: pssh 2.3.6-1.fc43 Β· LicenseRef-Callaway-BSD
- fedora 44: pssh 2.3.6-2.fc44 Β· LicenseRef-Callaway-BSD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms