Header Ads Widget

Ticker

6/recent/ticker-posts

Linux: cómo instalar y usar sshpass

Instalación:

Ejemplo para CentOS:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
dieciséis
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[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                                                     | 3.6 kB     00:00
epel                                                     | 4.7 kB     00:00
extras                                                   | 2.9 kB     00:00
ius                                                      | 1.3 kB     00:00
nodesource                                               | 2.5 kB     00:00
updates                                                  | 2.9 kB     00:00
(1/3): updates/7/x86_64/primary_db                         | 2.9 MB   00:00
(2/3): epel/x86_64/primary_db                              | 6.8 MB   00:00
(3/3): epel/x86_64/updateinfo                              | 1.0 MB   00:00
Resolving Dependencies
--> Running transaction 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           1.06-2.el7           extras            21 k
  
Transaction Summary
================================================================================
Install  1 Package
  
Total download size: 21 k
Installed size: 38 k
Downloading packages:
sshpass-1.06-2.el7.x86_64.rpm                              |  21 kB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : sshpass-1.06-2.el7.x86_64                                    1/1
  Verifying  : sshpass-1.06-2.el7.x86_64                                    1/1
  
Installed:
  sshpass.x86_64 0:1.06-2.el7
  
Complete!

Uso

sshpass puede aceptar la contraseña: como argumento, leerlo desde un archivo o mediante una variable de entorno.

Método 1: contraseña como argumento

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

Ejemplo:

1
2
3
4
[root@tutorialspots ~]# sshpass -p yourpassword ssh -o StrictHostKeyChecking=no -o LogLevel=quiet root@tutorialspots.com 'free -m'
              total        used        free      shared  buff/cache   available
Mem:          31923         888         471           0       30563       30643
Swap:         32733           5       32728

Método 2: contraseña del archivo

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

Método 3: contraseña de la variable de entorno

1
2
export SSHPASS="your-password"
sshpass -e ssh -o StrictHostKeyChecking=no -o LogLevel=quiet root@ip command

Publicar un comentario

0 Comentarios