标签:-- org nts tin shell命令 efi 服务 root shell
ssh登陆不能在命令行中指定密码。sshpass的出现,解决了这一问题。sshpass用于非交互SSH的密码验证,一般用在sh脚本中,无须再次输入密码。
它允许你用 -p 参数指定明文密码,然后直接登录远程服务器,它支持密码从命令行、文件、环境变量中读取。
下载如下:
https://sourceforge.net/projects/sshpass/
解压,安装
[root@localhost opt]# tar zxvf sshpass-1.06.tar.gz
[root@localhost opt]# cd sshpass-1.06/
[root@localhost sshpass-1.06]# ./configure --prefix=/opt/sshpass
[root@keep1 sshpass-1.06]# make
[root@keep1 sshpass-1.06]# make install
经过以上步骤,sshpass安装完成,输入命令 sshpass 如出现如下提示即安装成功:
[root@keep1 bin]# ./sshpass
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
-P prompt Which string should sshpass search for to detect a password prompt
-v Be verbose about what you‘re doing
-h Show help (this screen)
-V Print version information
At most one of -f, -d, -p or -e should be used
用法:
-p password
#后跟密码
[root@zhu ~]
# sshpass -p 目标机器的root密码 ssh root@IP地址
-f filename
#后跟保存密码的文件名,密码是文件内容的第一行。
[root@zhu ~]
# cat 1.txt
123456
[root@zhu ~]
# sshpass -f 1.txt ssh root@IP地址
-e
#将环境变量SSHPASS作为密码
[root@zhu ~]
# export SSHPASS=123456
[root@zhu ~]
# sshpass -e ssh root@IP地址
sshpass -p user_password ssh -o StrictHostKeyChecking=no user_name@IP地址
【-o StrictHostKeyChecking=no 表示远程连接时不提示是否输入yes/no】
使用sshpass远程免密,在远程主机上执行shell命令,如下远程执行命令:touch /opt/file.txt
sshpass -p user_password ssh -o StrictHostKeyChecking=no user_name@IP地址 touch /opt/file.txt
[注:shell命令要和sshpass命令写在一行]
标签:-- org nts tin shell命令 efi 服务 root shell
原文地址:https://www.cnblogs.com/zy6103/p/12153166.html