Pssh – Execute Commands On Multiple Remote Linux Servers Using Local System

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/pssh-execute-commands-multiple-remote-linux-servers-using-local-system/
PINTEREST
PINTEREST
INSTAGRAM

ssh  is very useful protocol and tool used by Linux system administrators. It provides easy, secure and fast access to the remote systems and servers. It also provides file copy between local and remote systems securely. But in an enterprise environment we generally need to run single command on multiple remote servers. In this case ssh command can help but it has some restrictions. We can use pssh  or parrallel ssh  to exceed restrictions.

Install Pssh For Debian, Ubuntu, Mint, Kali

We will start by installating  pssh  tool into deb or apt based systems like Debian, Ubuntu, Mint, Kali etc with the following command.

Install Pssh For Fedora, CentOS, RHEL

Syntax

We can install pssh into rpm or yumbased systems with the following command .

Install Pssh For Fedora, CentOS, RHEL Syntax

Install Pssh For Fedora, CentOS, RHEL Syntax

Remote Host Inventory

As we want to run single command on multiple remote systems the best way to specify remote systems is creating remote host inventory. So we will provide this inventory file to the pssh command. Inventory is just a text file where every remote host we want to run command is listed line by line. The location of the host inventory file is not important because we will specify it by hand. Here is an example host file. We can specify IP address to. Keep in mind that the hostnames should resolved by local or remote dns.

LEARN MORE  How To Generate Ssh Key With ssh-keygen In Linux

Run Given Command On Remote

Now we can use pssh in our local system. We will start with a simple command to run on remote system. We do not need any installation or change on the remote system to run commands with pssh . The command we want to run must be supported on the remote system. In this example we will use remote host inventory file named inventory and run command echo "Hello POFTUT" . The command will run with our local user name on the remote system.

Run Given Command On Remote

Run Given Command On Remote

Specify Remote Username

What if we need to use different user on the remote systems. We can specify the user name with the -l  login parameter. In this example we will specify the username root  for remote systems.

Specify Remote Username

Specify Remote Username

Print Command Output To Local Terminal

Up to now we have executed commands in the remote systems but do not get any feedback or output from commands. We can use -i interactive option which will bind remote systems command output to our local terminal and print output to our shell.

Print Command Output To Local Terminal

Print Command Output To Local Terminal

Save Standard Output To A File

In previous example we have printed command output to our local terminal. Another useful option provided by pssh is writing or saving this output into a file without any external command or app. We will use -o  option and provide the path . In this example we will set the output path as comm . For each remote host a text file will be created and the provided output will be saved.

LEARN MORE  Mobaxterm Installation and Usage For Windows Personal Edition

Save Standard Output To A File

Save Standard Output To A File

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/pssh-execute-commands-multiple-remote-linux-servers-using-local-system/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

2 Responses

  1. CertDepot says:

    Instead of Pssh, use a more powerful tool to do that: Ansible.

    • Thanks for contribution. I am definitely with you where Ansible has a lot of plus over pssh but in some cases pssh provides practical or compatible solutions to Linux system administrators.

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)