GNU/Linux >> Linux Esercitazione >  >> Linux

Comando sshpass:autenticazione password non interattiva con SSH

Panoramica

Gli amministratori del sistema Linux normalmente accedono ai server Linux fornendo una password o utilizzando l'autenticazione basata su chiave. sshpass è uno strumento che ci consente di fornire automaticamente password al prompt dei comandi in modo che gli script automatizzati possano essere eseguiti come desiderato dagli utenti. sshpass fornisce la password a ssh prompt usando tty dedicato, ingannando ssh facendogli credere che un utente interattivo stia fornendo una password.

Alcuni degli usi comuni di sshpass

1. eseguire backup su un server remoto
2. eseguire comandi sui sistemi a un'ora specificata.

Installazione sshpass

1. Distribuzioni basate su Centos:

Imposta il repository EPEL da https://fedoraproject.org/wiki/EPEL e poi come root run:

# yum -y install sshpass

2. Distribuzioni basate su Ubuntu/Debain:

Come esecuzione di root:

# apt-get install sshpass

3. Compila e installa dal sorgente:

# wget http://sourceforge.net/projects/sshpass/files/latest/download -O sshpass.tar.gz
# tar -zxvf sshpass.tar.gz 
# cd sshpass-1.05/ 
# ./configure 
# make 
# make install
# which sshpass
/usr/local/bin/sshpass

Ricevere aiuto

# sshpass -h
Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters

-f filename   Take password to use from file
-d number     Use number as file descriptor for getting password
-p password   Provide password as argument (security unwise)
-e            Password is passed as env-var "SSHPASS" With no parameters – password will be taken from stdin
-h            Show help (this screen)
-V            Print version information

Al massimo uno tra -f, -d, -p o -e dovrebbe essere usato

Esempio 1:fornire la password con ssh

# sshpass -p 'password' ssh ldap.thegeekdiary.com -l root -o StrictHostKeyChecking=no

Dove:

password è la password del tuo server (ldap.thegeekdiary.com). 'StrictHostKeyChecking=no ' viene utilizzato per controllare gli accessi a macchine la cui chiave host non è nota o è stata modificata.

ESEMPIO:2 PER ESEGUIRE ALCUNI COMANDI SUL SERVER REMOTO VIZ CONTROLLO UPTIME E UNAME

Esempio 2:eseguire alcuni comandi sul server remoto

Proviamo a eseguire 2 comandi "uptime" e "uname" sul server remoto usando il comando sshpass:

# sshpass -p 'password' ssh ldap.thegeekdiary.com -l root -o StrictHostKeyChecking=no "uptime;uname -a"

Esempio di output:

18:49:34 up 21 days, 18:49,  3 users,  load average: 0.01, 0.00, 0.00
Linux ldap.thegeekdiary.com 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/Linux

Esempio 3:copia di un file utilizzando rsync su un server

Nel nostro caso stiamo copiando un file sshpass.tar.gz su un server remoto ldap.thegeekdiary.com

# sshpass -p 'password' rsync -av --progress sshpass.tar.gz [email protected]:/tmp/

Output del comando precedente:

sending incremental file list
sshpass.tar.gz
98362 100% 62.56MB/s 0:00:00 (xfer#1, to-check=0/1)
sent 98472 bytes received 31 bytes 197006.00 bytes/sec
total size is 98362 speedup is 1.00
root@server1:/home/thegeekdiary#

Esempio 4:ciclo for per la copia su server remoti

Crea un file come il seguente:

# touch /tmp/scr

Il file dovrebbe contenere il nome degli host:

server2.thegeekdiary.com
server3.thegeekdiary.com
server4.thegeekdiary.com
server5.thegeekdiary.com
# for i in `cat /tmp/scr`; do echo " ";echo "###$i####"; sshpass -p 'password' rsync -av --progress sshpass.tar.gz root@$i:/tmp/; done

Output del comando sopra:

###server2.thegeekdiary.com####
sending incremental file list
sent 54 bytes received 12 bytes 132.00 bytes/sec
total size is 98362 speedup is 1490.33

###server3.thegeekdiary.com####
sending incremental file list
sent 54 bytes received 12 bytes 44.00 bytes/sec
total size is 98362 speedup is 1490.33

###server4.thegeekdiary.com####
sending incremental file list
sent 54 bytes received 12 bytes 132.00 bytes/sec
total size is 98362 speedup is 1490.33

###server5.thegeekdiary.com####
sending incremental file list
sent 54 bytes received 12 bytes 132.00 bytes/sec
total size is 98362 speedup is 1490.33


Linux
  1. SSHPass:come eseguire SSH in un server utilizzando uno script senza password (in modo non interattivo)

  2. Accesso Ssh con password in chiaro come parametro??

  3. Oring con True in un comando su Ssh?

  4. Invio di una password tramite SSH o SCP con subprocess.Popen

  5. Rsync con SSH che richiede la password remota

Test della password SSH con Hydra su Kali Linux

Come disabilitare l'autenticazione della password SSH su VPS Linux

Comando SSH

Disabilita l'autenticazione con password SSH per utenti o gruppi specifici

Come passare la password al comando SSH in Linux

Come impostare l'autenticazione della password con Apache su Ubuntu 18.04