Open In App

pssh linux comman

Last Updated : 26 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The “pssh” command in Linux stands for “parallel SSH,” and it is a powerful command designed for executing commands simultaneously on multiple remote servers. This tool simplifies and expedites the process of managing and administering a cluster of machines by allowing administrators to perform tasks in parallel, thereby saving time and effort. Pssh works by utilizing SSH (Secure Shell) to establish connections to remote hosts, enabling the execution of commands across multiple systems concurrently.

pssh Linux Command

A command-line utility called pssh, or Parallel SSH, allows you to perform commands on many remote computers simultaneously using SSH. It enables you to administer several remote servers or hosts at once more easily and automatically. Tasks like server management, software upgrades, and data synchronization among a cluster of devices might benefit greatly from this.

The PSSH utility contains OpenSSH parallel versions and associated utilities like:

  1. pscp: A tool called pscp is used to copy files simultaneously to many hosts.
  2. prsync: A tool called prsync effectively transfers files to many sites at once.
  3. pnuke – This terminates processes concurrently on several distant hosts.
  4. pslurp – This is a program that transfers data in parallel from several distant hosts to a central host.

Syntax of pssh Command in Linux:

pssh [OPTIONS] -h hosts_file -i COMMAND
  • [OPTIONS]: this flag modifies the behavior of pssh. Some common options include:
  • -h hosts_file: Specifies a file containing a list of target hosts. Each line in the file typically represents a hostname or an IP address.
  • -i COMMAND: The command to be executed on the remote hosts. This can be a single command or a series of commands separated by semicolons.

Commonly Used Options in the `pssh` command in Linux

Options

Description

-h or –hosts <file>

Read hosts from a file, each line in [user@]host[:port] format. Can use multiple host files.

-H [user@]host[:port] or –host [user@]host[:port]

Add specified hosts to the list. Can be used -h multiple times.

-l user or –user

Set default username for hosts without specified user.

-p parallelism or –par parallelism

Set max concurrent connections.

-e errdir or –errdir errdir

Save standard error to files in specified directory.

-X arg or –extra-arg arg

Do not handle a single SSH command-line argument.

-O alternatives or –options options

Specify SSH options in SSH configuration record format.

-A or –askpass

Prompt for a password securely for key unlocking or authentication.

-i or –inline

Show standard output and error when each host finishes.

–inline-stdout

Show standard output (no standard error) on each host finish.

-v or –verbose

Include SSH error messages with the -i option.

-P or –print

Show output as it comes in, interleaved from multiple hosts.

Exit Status in pssh Command

The pssh command returns exit status to indicate the success or failure of its execution. The exit status can be checked to determine if the command was completed successfully or if there were any issues. In general, a successful execution results in an exit status of 0, while non-zero values indicate errors or specific conditions.

Here are some common exit status values for pssh:

  • 0: The command was successful on all hosts.
  • 1: There was an error during the execution on one or more hosts.
  • 2: There was an issue with the command-line arguments or options.
  • 3: An error occurred while setting up the parallel connections.
  • 4: The execution was interrupted by the user.

Installation of pssh Command

In this section, we will see the installation process of pssh command on various Linux distributions. According to your distro, follow the commands and complete the installation.

1. Debian/Ubuntu Linux:

On Debian-based computers, the apt package manager may be used to install pssh.

$ sudo apt update
$ sudo apt install pssh
pssh Installation on Ubuntu

pssh Installation on Ubuntu

2. RedHat and CentOS:

You may use the yum or dnf package management on Red Hat-based systems.

$ sudo yum install pssh

3. Fedora:

Using Dnf to install pssh on Fedora:

$ sudo dnf install pssh

4. openSUSE:

Pssh may be installed on openSUSE by using the Zypper package manager:

$ sudo zypper install pssh

5. OSX/MacOS:

Install brew first then execute the command below:

$ brew install pssh

Practical Implementation of the ‘pssh’ command with Examples.

Firstly create a host file with the number of hosts, IP address, and port number.

touch hosts_file.txt
Creating Host File

Creating Host File

1. Print message to multiple servers:

Run the below to print the “Hello GeeksforGeeks” at the terminals of several Linux systems.

$ pssh -h hosts_file -l root -A echo "Hello GeeksforGeeks"
Print message to multiple servers

Print messages to multiple servers

This pssh command connects to the list of various hosts listed in hosts_file and uses SSH agent authentication to authenticate as the basic user, after which runs the echo “Hello GeeksforGeeks” command on every remote host. Each host will print “Hello GeeksforGeeks” on its standard output.

2. Get the disk usage of multiple servers:

To get the disk space use statistics for all the Linux servers and run the below command.

# pssh -h hosts_file -l root -A -i "df -hT"
Get the disk usage of multiple servers

Get the disk usage of multiple servers

  • h hosts_file: Specifies the path to a file containing a list of target hosts. Each line in the file represents a host.
  • -l root: Sets the login username to “root” for establishing SSH connections to the remote hosts.
  • -A: Prompts for the SSH password to authenticate to the remote hosts. This is useful when using password-based authentication instead of SSH keys.
  • -i: Enables interactive mode, allowing you to interact with each remote host in real-time. This is particularly helpful for commands that may require manual intervention.
  • "df -hT": The command to be executed on each remote host. In this case, it’s, which displays disk space usage and file system type.

To include the filesystem type inside the output, use the -T alternative when executing df.

3. Uptime of servers:

Using the pssh command to get the Uptime of several Linux servers at once.

$ pssh -h hosts_file -l root -A -i "uptime"
Uptime of servers

Uptime of servers

This pssh program will connect to the list of remote hosts listed in hosts_file, utilize SSH agent authentication to authenticate as the root user, and then run the uptime command on each remote host. This will show the load average and uptime statistics for each remote host on the system.

4. Get dates of multiple machines:

Using the pssh command to retrieve the dates on multiple hosts.

$ pssh -h hosts_file -i date
Get dates of multiple machines

Get dates of multiple machines

5. Get IP addresses of multiple devices:

Using the pssh command in Linux to display the IP addresses of multiple hosts :

$ pssh -i -H 192.168.0.10:22 -H 192.168.0.11:22 'echo $PSSH_NODENUM'
Get IP addresses of multiple devices

Get IP addresses of multiple devices

6. Check the version of pssh:

To display the version of the pssh, you can use the following command mentioned below:

$ pssh --version
Check the version of pssh

Check the version of pssh

Conclusion:

In conclusion, the “pssh” command in Linux, is a part of the parallel-ssh package, that is used for executing commands simultaneously across multiple remote hosts. With the ability to specify hosts through a file, customize login credentials, and facilitate interactive sessions, pssh enhances the efficiency of system administrators in managing and automating tasks in distributed computing environments. Whether performing updates, configuration changes, or troubleshooting, the parallel execution and output aggregation features make pssh a valuable command for streamlined and scalable Linux server management.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads