Parallel SSH: PSSH tool to connect Multiple SSH Servers at a Time

Parallel SSH: PSSH tool to connect Multiple SSH Servers at a Time

Parallel SSH: PSSH tool to connect Multiple SSH Servers at a Time

What is PSSH: Parallel SSH (pssh) is a totally free tool which is compatible with all OS like Unix and Linux, and allow us to connect simultaneously to multiple SSH servers to execute same commands at once, without having to go into each one of them to perform the same actions.

When a web or company has multiple servers, configured with the same operating system and the same versions of the software. If for example we want to modify something in a group of them, or update all the programs to the latest versions, we should need to login one by one and execute the same commands, so we will have a repetitive task. Related Post: SSH Tunnel configurations

what is PSSH

Thanks to tools such as PSSH, we can connect remotely to several SSH servers simultaneously, and execute the same command in all of them at once. So we will be automating to a large extent the entire process of deployment and update of these servers. Some important features of pssh is that it allows us to enter access passwords, so it is not necessary to have only private keys in the system.

Installation of PSH in Debian

This tool is available in all the repositories of the main distributions, we have tested it in Debian 8 and we are required the following command to install it correctly:

sudo apt-get install pssh

sudo apt-get install pssh

If you use FreeBSD you can use the pkg itself to install it and if you use systems based on Red Hat you can install it through yum. In your system it is likely that you can not execute the command “pssh” itself, but it is through the command “parallel-ssh” as you can see below:

How to use PSSH to connect simultaneously to Multiple SSH Servers

The easiest way to use this tool is to create a text file with all the hosts we want to connect to, the syntax is very simple, then you can see it:

[usuario@]IP_servidor[:puerto]

An example of our test text file:

 

All  PSSH commands have the form command -h hosts-file options, where the hosts_file representing a list of all hosts those we want to have for command executed on.

It is recommended that in the organization or in our home we make use of the cryptographic keys of SSH, not only because for security purpose, but because we will not have to enter the password to access each of the SSH servers to the that we want to connect

Once we have created the text file, we will use the following command:

parallel-ssh -i -h nombre_archivo_texto COMANDO

If for example we want to show the date of all the servers to which we have connected, it would be enough simply to do:

 pssh -i -h ~/.pssh_hosts_files date

pssh -i -H “host1 host2” echo “hello, world”

PSSH is a pretty good tool for parallel SSH command execution on multiple servers. It is quite useful if you have 5 to 10 SSH servers. I hope this is informative for you….

Waqas Azam
Me Waqas Azam and I am a professional blogger & freelance writer. I also working in the IT industry for over 7 years. I am graduated in Computer Science and information technology.