dotlinux blog

Pssh – Execute Commands on Multiple Remote Linux Servers

In a large - scale Linux environment, system administrators often need to execute commands on multiple remote servers simultaneously. Manually logging in to each server and running commands is time - consuming and error -prone. This is where Parallel SSH (Pssh) comes in handy. Pssh allows you to execute commands in parallel on multiple servers, improving efficiency and streamlining system management tasks. In this blog post, we will explore what Pssh is, how to install it, and how to use it effectively to execute commands on multiple remote Linux servers.

2026-06

Table of Contents#

  1. What is Pssh?
  2. Installation of Pssh
    • Installing on Ubuntu/Debian
    • Installing on CentOS/RHEL
  3. Prerequisites for Using Pssh
  4. Basic Usage of Pssh
    • Running a Simple Command
    • Controlling Parallelism
  5. Advanced Usage
    • Using Different Authentication Methods
    • Handling Output and Errors
  6. Limitations of Pssh
  7. Conclusion
  8. References

1. What is Pssh?#

Parallel SSH (Pssh) is a set of small SSH wrapper scripts that allow you to run commands in parallel on multiple remote hosts. The suite includes several commands like pssh (parallel SSH), pscp (parallel SCP), prsync (parallel Rsync), pnuke (parallel kill), and pslurp (parallel file retrieval). With Pssh, you can perform tasks such as software updates, log collection, and configuration changes across multiple servers at once.

2. Installation of Pssh#

Installing on Ubuntu/Debian#

To install Pssh on an Ubuntu or Debian system, you can use the following commands:

sudo apt-get update
sudo apt-get install pssh

The apt-get update command updates the package list, and apt-get install pssh installs the Pssh package.

Installing on CentOS/RHEL#

On CentOS or RHEL systems, you can install Pssh from the EPEL repository. First, enable the EPEL repository:

sudo yum install epel-release

Then, install Pssh:

sudo yum install pssh

3. Prerequisites for Using Pssh#

Before using Pssh, you need to ensure the following:

  • SSH Connectivity: You should be able to establish an SSH connection to all the remote servers from the machine where you are running Pssh.
  • Key - Based Authentication (Optional but Recommended): Using key - based authentication simplifies the process and eliminates the need to enter passwords for each server. You can generate an SSH key pair using the ssh-keygen command and distribute the public key to all the remote servers using ssh-copy-id.

4. Basic Usage of Pssh#

Running a Simple Command#

To run a simple command on multiple remote servers, you first need to create a text file containing the IP addresses or hostnames of the remote servers, one per line. For example, create a file named servers.txt:

192.168.1.100
192.168.1.101

You can then use the following command to run the ls command on all the servers in the servers.txt file:

pssh -h servers.txt ls

The -h option specifies the file containing the list of servers.

Controlling Parallelism#

By default, Pssh runs commands on all servers in parallel. However, you can control the number of concurrent connections using the -p option. For example, to limit the number of concurrent connections to 2:

pssh -h servers.txt -p 2 ls

5. Advanced Usage#

Using Different Authentication Methods#

  • Password Authentication: If you are using password - based authentication, you can use the -A option to prompt for the password:
pssh -h servers.txt -A ls

This will ask you to enter the password, which will then be used for all the servers.

  • Custom Key Location: If you are using key - based authentication and your private key is not in the default location (~/.ssh/id_rsa), you can specify the key location using the -x option to pass the -i flag to SSH:
pssh -h servers.txt -x "-i /path/to/your/private/key" ls

Handling Output and Errors#

  • Individual Output: You can use the -i option to display the individual output of each server:
pssh -h servers.txt - i ls
  • Logging Output: You can redirect the output to a file using the -o option for standard output and -e option for error output:
pssh -h servers.txt -o /path/to/output/dir -e /path/to/error/dir ls

6. Limitations of Pssh#

  • Error Handling: Pssh does not provide very sophisticated error handling. If a command fails on one server, it may not be immediately obvious how to diagnose and fix the issue.
  • Scalability: While Pssh can handle a moderate number of servers, for very large - scale deployments, more advanced tools like Ansible or SaltStack may be more suitable.

7. Conclusion#

Pssh is a powerful tool for system administrators to efficiently execute commands on multiple remote Linux servers. It is easy to install and use, and can significantly reduce the time and effort required for routine system management tasks. However, it has its limitations, and for more complex scenarios, you may need to consider other automation tools. With a good understanding of Pssh's features and capabilities, you can streamline your Linux server management operations.

8. References#