本文主要是介绍Shell命令sshpass非交互SSH密码验证,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
版权声明:本文为博主原创文章,未经博主允许不得转载。
Shell命令sshpass非交互SSH密码验证
#安装sshpasssshpass
下载地址:http://sourceforge.net/projects/sshpass/
下载为一个 tar.gz的压缩包。
$ tar -zxvf sshpass-1.05.tar.gz
$ cd sshpass-1.05
$ ./configure --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
#!/bin/bash
cd $(dirname $0)
source ./config.sh
date=`date +%Y-%m-%d`
#上传DUMP脚本到服务端
sshpass -pyour_pwd scp -P22 ./dump.sh your_user@192.168.1.10:~/
#-o StrictHostKeyChecking=no 避免第一次登录出现公钥检查。
sshpass -pyour_pwd scp -o StrictHostKeyChecking=no -P22 ./dump.sh your_user@192.168.1.10:~/
#登陆到服务端地址,执行DUMP脚本,将执行结果写入本地文件
sshpass -pyour_pwd ssh -p22 your_user @192.168.1.10 "sh ~/dump.sh" >local_result.txt
#使用文件中的密码
sshpass -f pwd.file ssh -p22 your_user@192.168.1.10 "sh ~/dump.sh" >>local_result.txt
#从环境变量(SSHPASS)读取密码
sshpass -e ssh -p22 your_user@192.168.1.10 "sh ~/dump.sh" >>local_result.txt
这篇关于Shell命令sshpass非交互SSH密码验证的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!