{"id":13460,"date":"2019-04-02T04:25:53","date_gmt":"2019-04-02T04:25:53","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13460"},"modified":"2019-04-02T04:25:53","modified_gmt":"2019-04-02T04:25:53","slug":"pssh-execute-commands-on-multiple-remote-linux-servers-using-single-terminal","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/02\/pssh-execute-commands-on-multiple-remote-linux-servers-using-single-terminal\/","title":{"rendered":"Pssh \u2013 Execute Commands on Multiple Remote Linux Servers Using Single Terminal"},"content":{"rendered":"<p>No doubt, that\u00a0<strong>OpenSSH<\/strong>\u00a0is one of the most widely used and powerful tool available for Linux, that allows you to connect securely to remote Linux systems via a shell and allows you to transfer files securely to and from remote systems.<\/p>\n<div id=\"attachment_15716\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Run-Commands-on-Multiple-Linux-Servers.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15716\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Run-Commands-on-Multiple-Linux-Servers-620x297.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Run-Commands-on-Multiple-Linux-Servers-620x297.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Run-Commands-on-Multiple-Linux-Servers.png 720w\" alt=\"Run Commands on Multiple Linux Servers\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-15716\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15716\" class=\"wp-caption-text\">Pssh \u2013 Run Commands on Multiple Linux Servers<\/p>\n<\/div>\n<p>But the biggest disadvantages of\u00a0<strong>OpenSSH<\/strong>\u00a0is that, you cannot execute same command on multiple hosts at one go and OpenSSH is not developed to perform such tasks. This is where\u00a0<strong>Parallel SSH<\/strong>\u00a0or\u00a0<strong>PSSH<\/strong>\u00a0tool comes in handy, is a python based application, which allows you to execute commands on multiple hosts in parallel at the same time.<\/p>\n<p><strong>Don\u2019t Miss<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/using-dsh-distributed-shell-to-run-linux-commands-across-multiple-machines\/\" target=\"_blank\" rel=\"noopener\">Execute Commands on Multiple Linux Servers Using DSH Tool<\/a><\/p>\n<p><strong>PSSH<\/strong>\u00a0tool includes parallel versions of OpenSSH and related tools such as:<\/p>\n<ol>\n<li><b>pssh<\/b>\u00a0\u2013 is a program for running ssh in parallel on a multiple remote hosts.<\/li>\n<li><strong>pscp<\/strong>\u00a0\u2013 is a program for copying files in parallel to a number of hosts.\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/copy-files-to-multiple-linux-servers\/\" target=\"_blank\" rel=\"noopener\">Pscp \u2013 Copy\/Transfer Files Two or More Remote Linux Servers<\/a><\/li>\n<\/ol>\n<\/li>\n<li><strong>prsync<\/strong>\u00a0\u2013 is a program for efficiently copying files to multiple hosts in parallel.<\/li>\n<li><strong>pnuke<\/strong>\u00a0\u2013 kills processes on multiple remote hosts in parallel.<\/li>\n<li><strong>pslurp<\/strong>\u00a0\u2013 copies files from multiple remote hosts to a central host in parallel.<\/li>\n<\/ol>\n<p>These tools are good for System Administrators who find themselves working with large collections of nodes on a network.<\/p>\n<h3>Install PSSH or Parallel SSH on Linux<\/h3>\n<p>In this guide, we shall look at steps to install the latest version of PSSH (i.e. version\u00a0<strong>2.3.1<\/strong>) program on\u00a0<strong>Fedora<\/strong>based distributions such as\u00a0<strong>CentOS<\/strong>\/<strong>RedHat<\/strong>\u00a0and\u00a0<strong>Debian<\/strong>\u00a0derivatives such as\u00a0<strong>Ubuntu<\/strong>\/<strong>Mint<\/strong>\u00a0using\u00a0<strong>pip<\/strong>\u00a0command.<\/p>\n<p>The\u00a0<strong>pip<\/strong>\u00a0command is a small program (replacement of\u00a0<strong>easy_install<\/strong>\u00a0script) for installing and managing Python software packages index.<\/p>\n<h4>On Fedora based Distributions<\/h4>\n<p>On\u00a0<strong>CentOS<\/strong>\/<strong>RHEL<\/strong>\u00a0distributions, you need to first install pip (i.e. python-pip) package under your system, in order to install PSSH program.<\/p>\n<pre># yum install python-pip\r\n<\/pre>\n<p>On\u00a0<strong>Fedora 21+<\/strong>, you need to run\u00a0<a href=\"https:\/\/www.tecmint.com\/dnf-commands-for-fedora-rpm-package-management\/\" target=\"_blank\" rel=\"noopener\">dnf command<\/a>\u00a0instead yum (<strong>dnf replaced yum<\/strong>).<\/p>\n<pre># dnf install python-pip\r\n<\/pre>\n<p>Once you\u2019ve install pip tool, you can install the pssh package with the help of pip command as shown.<\/p>\n<pre># pip install pssh  \r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>\/usr\/lib\/python2.6\/site-packages\/pip\/_vendor\/requests\/packages\/urllib3\/util\/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https:\/\/urllib3.readthedocs.org\/en\/latest\/security.html#insecureplatformwarning.\r\n  InsecurePlatformWarning\r\nYou are using pip version 7.1.0, however version 7.1.2 is available.\r\nYou should consider upgrading via the 'pip install --upgrade pip' command.\r\nCollecting pssh\r\n\/usr\/lib\/python2.6\/site-packages\/pip\/_vendor\/requests\/packages\/urllib3\/util\/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https:\/\/urllib3.readthedocs.org\/en\/latest\/security.html#insecureplatformwarning.\r\n  InsecurePlatformWarning\r\n  Downloading pssh-2.3.1.tar.gz\r\nInstalling collected packages: pssh\r\n  Running setup.py install for pssh\r\nSuccessfully installed <strong>pssh-2.3.1<\/strong>\r\n<\/pre>\n<h4>On Debian Derivatives<\/h4>\n<p>On Debian based distributions it takes a minute to install pssh using pip command.<\/p>\n<pre>$ sudo apt-get install python-pip\r\n$ sudo pip install pssh\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>Downloading\/unpacking pssh\r\n  Downloading pssh-2.3.1.tar.gz\r\n  Running setup.py (path:\/tmp\/pip_build_root\/pssh\/setup.py) egg_info for package pssh\r\n    \r\nInstalling collected packages: pssh\r\n  Running setup.py install for pssh\r\n    changing mode of build\/scripts-2.7\/pssh from 644 to 755\r\n    changing mode of build\/scripts-2.7\/pnuke from 644 to 755\r\n    changing mode of build\/scripts-2.7\/prsync from 644 to 755\r\n    changing mode of build\/scripts-2.7\/pslurp from 644 to 755\r\n    changing mode of build\/scripts-2.7\/pscp from 644 to 755\r\n    changing mode of build\/scripts-2.7\/pssh-askpass from 644 to 755\r\n    \r\n    changing mode of \/usr\/local\/bin\/pscp to 755\r\n    changing mode of \/usr\/local\/bin\/pssh-askpass to 755\r\n    changing mode of \/usr\/local\/bin\/pssh to 755\r\n    changing mode of \/usr\/local\/bin\/prsync to 755\r\n    changing mode of \/usr\/local\/bin\/pnuke to 755\r\n    changing mode of \/usr\/local\/bin\/pslurp to 755\r\nSuccessfully installed <strong>pssh<\/strong>\r\nCleaning up...\r\n<\/pre>\n<p>As you can see from the output above, the latest version of pssh is already installed on the system.<\/p>\n<h3>How do I Use pssh?<\/h3>\n<p>When using\u00a0<strong>pssh<\/strong>\u00a0you need to create a host file with the number of hosts along with IP address and port number that you need to connect to remote systems using pssh.<\/p>\n<p>The lines in the host file are in the following form and can also include blank lines and comments.<\/p>\n<div class=\"code-label\" title=\"pssh file with hosts\">pssh hosts file<\/div>\n<pre>192.168.0.10:22\r\n192.168.0.11:22\r\n<\/pre>\n<h6>Executing single command on multiple server using pssh<\/h6>\n<p>You can execute any single command on different or multiple Linux hosts on a network by running a\u00a0<strong>pssh<\/strong>command. There are many options to use with\u00a0<strong>pssh<\/strong>\u00a0as described below:<\/p>\n<p>We shall look at a few ways of executing commands on a number of hosts using pssh with different options.<\/p>\n<ol>\n<li>To read hosts file, include the\u00a0<strong>-h host_file-name<\/strong>\u00a0or\u00a0<strong>\u2013hosts host_file_name<\/strong>\u00a0option.<\/li>\n<li>To include a default username on all hosts that do not define a specific user, use the\u00a0<strong>-l<\/strong>\u00a0username or\u00a0<strong>\u2013user username<\/strong>\u00a0option.<\/li>\n<li>You can also display standard output and standard error as each host completes. By using the\u00a0<strong>-i<\/strong>\u00a0or\u00a0<strong>\u2013inline<\/strong>option.<\/li>\n<li>You may wish to make connections time out after the given number of seconds by including the\u00a0<strong>-t number_of_seconds<\/strong>\u00a0option.<\/li>\n<li>To save standard output to a given directory, you can use the\u00a0<strong>-o \/directory\/path<\/strong>\u00a0option.<\/li>\n<li>To ask for a password and send to ssh, use the\u00a0<strong>-A<\/strong>\u00a0option.<\/li>\n<\/ol>\n<p>Let\u2019s see few examples and usage of pssh commands:<\/p>\n<p><strong>1.<\/strong>\u00a0To execute\u00a0<strong>echo \u201cHello TecMint\u201d<\/strong>\u00a0on the terminal of the multiple Linux hosts by root user and prompt for the root user\u2019s password, run this command below.<\/p>\n<p><strong>Important<\/strong>: Remember all the hosts must be included in the host file.<\/p>\n<pre># pssh -h pssh-hosts -l root -A echo \"Hello TecMint\"\r\n\r\nWarning: do not enter your password if anyone else has superuser\r\nprivileges or access to your account.\r\nPassword: \r\n<strong>[1] 15:54:55 [SUCCESS] 192.168.0.10:22<\/strong>\r\n<strong>[2] 15:54:56 [SUCCESS] 192.168.0.11:22<\/strong>\r\n<\/pre>\n<p><strong>Note<\/strong>: In the above command \u201c<strong>pssh-hosts<\/strong>\u201d is a file with list of remote Linux servers IP address and SSH port number that you wish to execute commands.<\/p>\n<p><strong>2.<\/strong>\u00a0To find out the disk space usage on multiple Linux servers on your network, you can run a single command as follows.<\/p>\n<pre># pssh -h pssh-hosts -l root -A -i \"df -hT\"\r\n\r\nWarning: do not enter your password if anyone else has superuser\r\nprivileges or access to your account.\r\nPassword: \r\n<strong>[1] 16:04:18 [SUCCESS] 192.168.0.10:22<\/strong>\r\nFilesystem     Type   Size  Used Avail Use% Mounted on\r\n\/dev\/sda3      ext4    38G  4.3G   32G  12% \/\r\ntmpfs          tmpfs  499M     0  499M   0% \/dev\/shm\r\n\/dev\/sda1      ext4   190M   25M  156M  14% \/boot\r\n\r\n<strong>[2] 16:04:18 [SUCCESS] 192.168.0.11:22<\/strong>\r\nFilesystem              Type      Size  Used Avail Use% Mounted on\r\n\/dev\/mapper\/centos-root xfs        30G  9.8G   20G  34% \/\r\ndevtmpfs                devtmpfs  488M     0  488M   0% \/dev\r\ntmpfs                   tmpfs     497M  148K  497M   1% \/dev\/shm\r\ntmpfs                   tmpfs     497M  7.0M  490M   2% \/run\r\ntmpfs                   tmpfs     497M     0  497M   0% \/sys\/fs\/cgroup\r\n\/dev\/sda1               xfs       497M  166M  332M  34% \/boot\r\n<\/pre>\n<p><strong>3.<\/strong>\u00a0If you wish to know the\u00a0<strong>uptime<\/strong>\u00a0of multiple Linux servers at one go, then you can run the following command.<\/p>\n<pre># pssh -h pssh-hosts -l root -A -i \"uptime\"\r\nWarning: do not enter your password if anyone else has superuser\r\nprivileges or access to your account.\r\nPassword: \r\n<strong>[1] 16:09:03 [SUCCESS] 192.168.0.10:22<\/strong>\r\n 16:09:01 up  1:00,  2 users,  load average: 0.07, 0.02, 0.00\r\n\r\n<strong>[2] 16:09:03 [SUCCESS] 192.168.0.11:22<\/strong>\r\n 06:39:03 up  1:00,  2 users,  load average: 0.00, 0.06, 0.09\r\n<\/pre>\n<p>You can view the manual entry page for the\u00a0<strong>pssh<\/strong>\u00a0command to get many other options to find out more ways of using pssh.<\/p>\n<pre># pssh --help\r\n<\/pre>\n<div id=\"attachment_15711\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/pssh-commands.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15711\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/pssh-commands-620x443.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/pssh-commands-620x443.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/pssh-commands.png 906w\" alt=\"pssh commands and usages\" width=\"620\" height=\"443\" aria-describedby=\"caption-attachment-15711\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15711\" class=\"wp-caption-text\">pssh commands and usages<\/p>\n<\/div>\n<h3>Summary<\/h3>\n<p><strong>Parallel SSH<\/strong>\u00a0or\u00a0<strong>PSSH<\/strong>\u00a0is a good tool to use for executing commands in an environment where a\u00a0<strong>System Administrator<\/strong>\u00a0has to work with many servers on a network. It will make it easy for commands to be executed remotely on different hosts on a network.<\/p>\n<p>Hope you find this guide useful and incase of any additional information about pssh or errors while installing or using it, feel free to post a comment.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/execute-commands-on-multiple-linux-servers-using-pssh\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>No doubt, that\u00a0OpenSSH\u00a0is one of the most widely used and powerful tool available for Linux, that allows you to connect securely to remote Linux systems via a shell and allows you to transfer files securely to and from remote systems. Pssh \u2013 Run Commands on Multiple Linux Servers But the biggest disadvantages of\u00a0OpenSSH\u00a0is that, you &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/02\/pssh-execute-commands-on-multiple-remote-linux-servers-using-single-terminal\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Pssh \u2013 Execute Commands on Multiple Remote Linux Servers Using Single Terminal&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13460","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13460"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13460\/revisions"}],"predecessor-version":[{"id":13461,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13460\/revisions\/13461"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}