Linux: how to install and use sshpass

Installation:

Example for CentOS:

[root@tutorialspots ~]# yum install -y sshpass Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile epel/x86_64/metalink                                     |  13 kB     00:00  * base: linux.darkpenguin.net  * epel: mirror.imt-systems.com  * extras: mirror.checkdomain.de  * updates: mirror.fra10.de.leaseweb.net base of operations                                                     | 3.6 kB     00:00 epel                                                     | four.7 kB     00:00 extras                                                   | 2.9 kB     00:00 ius                                                      | 1.3 kB     00:00 nodesource                                               | ii.5 kB     00:00 updates                                                  | 2.9 kB     00:00 (1/three): updates/seven/x86_64/primary_db                         | 2.9 MB   00:00 (ii/3): epel/x86_64/primary_db                              | vi.8 MB   00:00 (iii/three): epel/x86_64/updateinfo                              | 1.0 MB   00:00 Resolving Dependencies --> Running transaction bank check ---> Package sshpass.x86_64 0:1.06-2.el7 will be installed --> Finished Dependency Resolution   Dependencies Resolved   ================================================================================  Package           Arch             Version              Repository        Size ================================================================================ Installing:  sshpass           x86_64           one.06-two.el7           extras            21 k   Transaction Summary ================================================================================ Install  i Packet   Full download size: 21 g Installed size: 38 thou Downloading packages: sshpass-one.06-2.el7.x86_64.rpm                              |  21 kB   00:00 Running transaction check Running transaction test Transaction exam succeeded Running transaction   Installing : sshpass-1.06-two.el7.x86_64                                    1/i   Verifying  : sshpass-1.06-ii.el7.x86_64                                    i/1   Installed:   sshpass.x86_64 0:1.06-2.el7   Complete!

Usage

sshpass tin accept countersign – as an argument, read it from file or via environment variable.

Method 1: Password as an statement

sshpass -p yourpassword ssh -o StrictHostKeyChecking=no -o LogLevel=quiet root@ip command

Example:

[root@tutorialspots ~]# sshpass -p yourpassword ssh -o StrictHostKeyChecking=no -o LogLevel=placidity root@tutorialspots.com 'free -m'               total        used        gratis      shared  buff/enshroud   bachelor Mem:          31923         888         471           0       30563       30643 Swap:         32733           5       32728

Method 2: Password from file

sshpass -f password-file ssh -o StrictHostKeyChecking=no -o LogLevel=quiet root@ip command

Method iii: Countersign from environment variable

export SSHPASS="your-countersign" sshpass -e ssh -o StrictHostKeyChecking=no -o LogLevel=quiet root@ip control