Table of Contents
In this article I will take you through 11 Useful PSSH Command Examples to Perform Parallel SSH in Multiple Linux Servers. You might be familiar with ssh tool which we often use to run some command or perform certain task on remote host. pssh(parallel-ssh) tool is the more advanced version of ssh command which comes with certain added advantages like pssh(parallel-ssh) tools can run certain commands in multiple hosts at the same time whereas ssh can run a command in only one remote host at any specific time.
You can still achieve the task of running a command in multiple remote hosts through ssh tool by using a short script but pssh makes the job a lot simpler by launching parallel ssh connections in all the remote nodes at the same time. pssh command along with other commands like pscp.pssh, pnuke, prsync and pslurp are very handy in running certain tasks or commands on multiple hosts at the same time using just a single command. You will understand more on the usage of pssh(parallel-ssh) based tools as we go further.
- pssh command – pssh is a program for executing ssh in parallel on a number of hosts. Check more on pssh man page.
- pscp.pssh command – pscp.pssh is a program for copying files in parallel to a number of hosts. Check more on pscp man page.
- prsync command – prsync is a program for copying files in parallel to a number of hosts. Check more on prsync man page.
- pnuke command – pnuke is a program for killing processes in parallel on a number of hosts. Check more on pnuke man page.
- pslurp command – pslurp is a program for copying files in parallel from a number of hosts. Check more on pslurp man page.
pssh command examples in Linux
Also Read: 15 Popular pssh command examples in Linux to Perform parallel ssh in a Single Command
Example 1: How to Check pssh command installation in Ubuntu/Debian Based Systems
If you want to check the installation of pssh command in Ubuntu Based Systems then you need to use apt list --installed
and grep for pssh(parallel-ssh) tool as you can see below. As you can see from below output current installed version is 2.3.1-1
.
[root@localhost ~]# apt list --installed | grep pssh pssh/bionic,bionic,now 2.3.1-1 all [installed]
NOTE:
root
user to run all the below commands.You can use any user with sudo
access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo
access to the User.Example 2: How to Check pssh tools installation path on Ubuntu/Debian Based Systems
If you want to check pssh(parallel-ssh) tools installation path on Ubuntu/Debian Based Systems then you need to use dpkg -L pssh
command as shown below. If you want you can only grep the bin to find the path of all pssh(parallel-ssh) based tools and narrow down your output.
[root@localhost ~]# dpkg -L pssh /. /usr /usr/bin /usr/bin/parallel-scp /usr/bin/parallel-ssh /usr/bin/parallel-rsync /usr/bin/parallel-slurp /usr/bin/parallel-nuke /usr/share /usr/share/doc /usr/share/doc/pssh /usr/share/doc/pssh/copyright /usr/share/doc/pssh/README.Debian /usr/share/doc/pssh/changelog.Debian.gz /usr/share/man /usr/share/man/man1 .....................................................................................................
Example 3: How to Check pssh(parallel-ssh) installation path on RHEL/CentOS Based Systems
If you want to check pssh tools installation path on RHEL/CentOS Based Systems then you need to use rpm -ql pssh
command and grep bin path from the output as shown below.
[root@localhost ~]# rpm -ql pssh | grep -i bin /usr/bin/pnuke /usr/bin/prsync /usr/bin/pscp.pssh /usr/bin/pslurp /usr/bin/pssh
Example 4: How to Install pssh command in Ubuntu/Debian Based Systems
If you want to install pssh command in Ubuntu/Debian Based Systems then you need to use apt-get install pssh -y
command as shown below.
root@localhost:~# apt-get install pssh -y Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: pssh 0 upgraded, 1 newly installed, 0 to remove and 199 not upgraded. Need to get 29.0 kB of archives. After this operation, 135 kB of additional disk space will be used. Get:1 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 pssh all 2.3.1-1 [29.0 kB] Fetched 29.0 kB in 0s (165 kB/s) Selecting previously unselected package pssh. (Reading database ... 288243 files and directories currently installed.) Preparing to unpack .../archives/pssh_2.3.1-1_all.deb ... Unpacking pssh (2.3.1-1) ... Setting up pssh (2.3.1-1) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Example 5: How to Install pssh command in RHEL/CentOS Based Systems
If you want to install pssh command in RHEL/CentOS Based Systems then you need to use yum install pssh -y
command as shown below.
[root@localhost ~]# yum install pssh -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.piconets.webwerks.in * epel: hkg.mirror.rackspace.com * extras: mirrors.piconets.webwerks.in * updates: mirrors.piconets.webwerks.in Resolving Dependencies --> Running transaction check ---> Package pssh.noarch 0:2.3.1-5.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================== Package Arch Version Repository Size ======================================================================================================================================================================== Installing: pssh noarch 2.3.1-5.el7 epel 49 k Transaction Summary ======================================================================================================================================================================== Install 1 Package Total download size: 49 k Installed size: 115 k Downloading packages: pssh-2.3.1-5.el7.noarch.rpm | 49 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : pssh-2.3.1-5.el7.noarch 1/1 Verifying : pssh-2.3.1-5.el7.noarch 1/1 Installed: pssh.noarch 0:2.3.1-5.el7 Complete!
Example 6: How to Check pssh tools command version
You can check parallel-ssh
version by using parallel-ssh --version
command as you can see below.
root@localhost:~# parallel-ssh --version 2.3.1
You can check parallel-nuke
version by using parallel-nuke --version
command as you can see below.
root@localhost:~# parallel-nuke --version 2.3.1
You can check parallel-rsync
version by using parallel-rsync --version
command as you can see below.
root@localhost:~# parallel-rsync --version 2.3.1
You can check parallel-slurp
version by using parallel-slurp --version
command as you can see below.
root@localhost:~# parallel-slurp --version 2.3.1
You can check parallel-scp
version by using parallel-scp --version
command as you can see below.
root@localhost:~# parallel-scp --version 2.3.1
Example 7: How to kill a Process in Multiple Hosts using pnuke
If you want to kill some process in multiple hosts then you can use pnuke
command as shown below. In this example we are trying to kill top
process running on nodes 192.168.0.105
and 192.168.0.106
using pnuke -h hosts top
command as shown below.
[root@localhost ~]# pnuke -h hosts top [1] 19:05:41 [SUCCESS] root@192.168.0.105 [2] 19:05:41 [SUCCESS] test@192.168.0.106
-h : Read hosts from the given host_file.
Example 8: How to Copy a file into Multiple hosts using pscp.pssh
If you want to copy a file into multiple hosts then you can use pscp.pssh
command as shown below. In this example, we are trying to copy file2.txt
from /root
source path to /tmp
destination path using pscp.pssh -h hosts /root/file2.txt /tmp
command as shown below.
[root@localhost ~]# pscp.pssh -h hosts /root/file2.txt /tmp [1] 20:46:58 [SUCCESS] root@192.168.0.105 [2] 20:46:58 [SUCCESS] test@192.168.0.106
-h : Read hosts from the given host_file.
Example 9: How to Sync Files with Multiple Remote Hosts using prsync
If you want to sync files with multiple remote hosts then you can use another important pssh tool called prsync
. In this example, we are trying to sync local file2.txt
with /tmp
of remote nodes 192.168.0.105
and 192.168.0.107
using below prsync
command through root
user.
[root@localhost ~]# prsync -H "192.168.0.105 192.168.0.107" -l root /root/file2.txt /tmp [1] 02:57:10 [SUCCESS] 192.168.0.107 [2] 02:57:10 [SUCCESS] 192.168.0.105
-H : Add the given host strings to the list of hosts.
-l : Use the given username as the default for any host entries that don’t specifically specify a user.
NOTE:
rsync
to be installed in your System else while running prsync
command you will get "OSError: [Errno 2] No such file or directory"
error. To know more about rsync command you can check 26 Popular rsync examples for Linux Professionals.Example 10: How to download File from Remote Host Using pslurp
If you want to download a file from multiple hosts and wanted to store it in a Central Location then you need to use pslurp command as shown below. In this example, we are trying to download /tmp/file2.txt
from remote hosts 192.168.0.105
and 192.168.0.107
and saving it as file3.txt
under example
directory in current location. Under directory example
, you will again find two directories created with the name of remote hosts (i.e 192.168.0.105
and 192.168.0.107
) under which you will find saved file3.txt
.
[root@localhost ~]# pslurp -H "192.168.0.105 192.168.0.107" -L example /tmp/file2.txt file3.txt [1] 03:13:23 [SUCCESS] 192.168.0.105 [2] 03:13:23 [SUCCESS] 192.168.0.107
-H : Add the given host strings to the list of hosts.
-L : Copy files from the remote host to the given local directory.
Example 11: How to Check pssh command version
You can check pscp.pssh
version by using parallel-ssh --version
command as shown below.
[root@localhost ~]# pscp.pssh --version 2.3.1
You can check pssh
version by using pssh --version
command as shown below.
[root@localhost ~]# pssh --version 2.3.1
You can check pnuke version by using
pnuke --version
command as shown below.
[root@localhost ~]# pnuke --version 2.3.1
You can check pslurp
version by using pslurp --version
command as shown below.
[root@localhost ~]# pslurp --version 2.3.1
You can check prsync
version by using prsync --version
command as shown below.
[root@localhost ~]# prsync --version 2.3.1
Recommended Posts:-
Understanding Kafka Console Producer and Consumer in 10 Easy Steps
Popular firewalld examples to open a port on RedHat/CentOS 7
8 Most Popular mkdir command in Linux with Examples
26 Useful Firewall CMD Examples on RedHat/CentOS 7
12 Most Popular rm command in Linux with Examples
9 useful w command in Linux with Examples
Popular Apache Kafka Architecture Explained Using 4 Basic Components
5 Easy Steps to recover LVM2 Partition , PV , VG , LVM metadata in Linux