sshpass访问Linux服务器(sshpass)

Shell命令,sshpass,非交互SSH密码验证,访问

 

一:安装sshpass

       下载地址:http://sourceforge.net/projects/sshpass/

        my下载地址:sshpass-1.05.tar.gz

二:下载完为一个例如:sshpass-1.05.tar.gz,压缩包      

	#解压并安装
	
	$ tar -zxvf sshpass-1.05.tar.gz

	$ cd sshpass-1.05

	$ ./configure --prefix=/opt/sshpass

	#指定安装目录 --prefix=/opt/sshpass(也可不指定)

	$ make

	$ make install

	$ cp /opt/sshpass/bin/sshpass /usr/bin/

    #安装完成

三:安装完成测试,#查看帮助:  

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
At most one of -f, -d, -p or -e should be used
四:登陆使用:
sshpass非交互SSH有密码验证登陆:
sshpass -p passroot ssh -p22  [email protected]
或
sshpass -p passroot ssh -o StrictHostKeyChecking=no -tt [email protected]
注:root为登录名,passroot为登陆密码,192.168.10.55为预登陆的ip地址
注:Shell命令sshpass非交互SSH有密码验证
       -tt  防止脚本调用ssh后出现Pseudo-terminal will not be allocated because stdin is not a terminal问题
       -o StrictHostKeyChecking=no 避免第一次登录出现公钥检查
五:配合shell使用:

详细见:my 博客“Linux下远程备份、上传工程,重启服务器

#上传xxx脚本到服务端
sshpass -p pwd scp -P22 ./xxx.sh [email protected]:~/
#-o StrictHostKeyChecking=no 避免第一次登录出现公钥检查。
sshpass -p pwd scp -o StrictHostKeyChecking=no -P22 ./xxx.sh [email protected]:~/
#登陆到服务端地址,执行xxx脚本,将执行结果写入本地文件
sshpass -p pwd ssh -p22 user @127.0.0.1 "sh ~/xxx.sh" >pwdss.txt
#使用文件中的密码
sshpass -f pwd.file ssh -p22 [email protected] "sh ~/xxx.sh" >>pwdss.txt
#从环境变量(SSHPASS)读取密码
sshpass -e ssh -p22 [email protected] "sh ~/xxx.sh" >>pwdss.txt

你可能感兴趣的:(sshpass访问Linux服务器(sshpass))