Sunday , December 22 2024

How To Run Single Command on Multiple Linux Servers

If you have more than one server you manage and if you connect to multiple servers with ssh and run single command on multiple linux servers, this article is for you.

If you want to run single command on multiple servers without connecting with ssh and read data from all servers with a single command, there are opensource tools like pssh, cssh. In this article I will talk about pssh.

What is PSSH?

Pssh stands for Parallel Security Shell. As I mentioned above, instead of connecting to the servers individually with SSH, we copy the sshkeys from the host server to the other servers. We send the queries with the help of a single command via the host (it can be your own local computer) and get the results.

Commands such as Pssh, Pscp, P-rysnc are also available. Before starting the installation, I must say that it requires an epel repo and you need to copy the ssh key of the host to other servers.

You may want to read the article below to create and copy ssh key.

How To Create Ssh Key and Connect Another Machine by Copying SSH Key

How To Install PSSH?

We run the command below for pssh installation.

After the installation is completed, we create host.txt as below and write the hosts into this file.

Just write username and machine names in the screenshot above. Because we created ssh key and copied it to other servers. After writing in the above format, we save and exit and run the pssh command as follows.

In the above command, it listed the disks on 3 servers at the same time with one command as seen below.

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *