Sshpass Configuration Installation
I. Introduction of Sshpass
SSH login can not specify the password on the command line, user interaction needs to enter the password, sshpass, solve the problem. It allows you to specify the clear-text password with the-p parameter and then directly to the remote server.
It allows passwords to be read from the command line, files, and environment variables. Therefore, the password is provided for SSH in a non-interactive form through the Sshpass implementation.
Second, installation configuration
1, Download: Currently 1.0.5 is the latest version,:
wget http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz
2. Compile and install
#tar XF sshpass-1.05.tar.gz
#cd sshpass-1.05
#./configure
#make && make Install
To see whether the installation succeeded:
#which Sshpass
/usr/local/bin/sshpass--the installation was successful.
3. Sshpass Usage and command introduction
#sshpass-H--View Help
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 would be taken from stdin
-H Show Help
-V Print Version information
At most one of-f,-D,-p OR-E should be used
Iii. Examples of usage
1. Pass the password from the command line mode
When the SSH port is default 22:
#sshpass-P userpassword ssh [email protected]
SSH port is not the default when 22, if 1234
#sshpass-P userpassword ssh-p1234 [email protected]
2. Read the password from the file
#echo "UserPassword" > MYPASSWD
#sshpass-F mypasswd ssh [email protected]
Problems encountered:
The first time you use Sshpass to log on to another server from one server, you sometimes perform
#sshpass-P userpassword ssh [email protected] command, no response, no error, and cannot log on to another server
Reason: For the first time SSH login, will prompt: "Is you sure want to continue connecting (yes/no)", then Sshpass will not make
Workaround: You can add-o stricthostkeychecking=no after the SSH command to resolve
Such as:
#sshpass-P userpassword ssh-o stricthostkeychecking=no [email protected]
warning:permanently added ' 10.0.18.156 ' (RSA) to the list of known hosts.
Last Login:thu Nov 5 17:37:51 from 10.0.18.157
So the landing is successful.
If you do not want to add the-o stricthostkeychecking=no parameter to the command line, you can modify it in the sshd configuration file
Set Stricthostkeychecking No in the Modify/etc/ssh/ssh_config file on all machines (default is #StrictHostKeyChecking ask)
3. Get the password from the environment variable (test is possible)
#export sshpass= "User_password"
#sshpass-e ssh [email protected]
Iv. a small case of practical work
After periodically modifying the server (hundred or so) password, verify that the modification is successful
#cat server_list.cfg
Web1
Web2
Web3
#cat check_passwd.sh
#!/bin/bash
Ips= ' Cat server_list.cfg '
For IP in $ips
Do
echo ========== $ip ===========
Sshpass-p "Server_password" ssh [email protected] $ip ":"
[$?-eq 0] && echo-e "\033[32m = = $ip ==password is ok ... \033[0m" | | echo-e "\033[31m = = $ip ==password is error !!! \033[0m "
Done
Alternatively, you can store the password in a file and use the-f parameter to get the password
Sshpass Configuration and Usage Introduction