经常我们使用脚本登入服务器的时候,如果使用ssh 命令,经常会提示密码输入,我们不得不手动输入密码,因为ssh 没有 密码的选项。
为了能绕过交互式验证,我们使用sshpass命令解决这个问题:
1. 安装
➜ Desktop sudo yum install sshpass [sudo] password for xuyaowen: Last metadata expiration check: 0:04:22 ago on Mon 02 Jul 2018 11:25:32 AM CST. Package sshpass-1.06-5.fc28.x86_64 is already installed, skipping. Dependencies resolved. Nothing to do. Complete!
检查是否安装
[root@yaowenxu Desktop]# rpm -qa sshpass sshpass-1.06-5.fc28.x86_64
2. 查看 sshpass 命令帮助, 也可以使用 man sshpass
NAME sshpass - noninteractive ssh password provider SYNOPSIS sshpass [-ffilename|-dnum|-ppassword|-e] [options] command arguments DESCRIPTION This manual page documents the sshpass command. sshpass is a utility designed for running ssh using the mode referred to as "keyboard-interactive" password authentication, but in non-interactive mode. ssh uses direct TTY access to make sure that the password is indeed issued by an interactive keyboard user. Sshpass runs ssh in a dedicated tty, fooling it into thinking it is getting the password from an interactive user. The command to run is specified after sshpass' own options. Typically it will be "ssh" with arguments, but it can just as well be any other command. The password prompt used by ssh is, however, currently hardcoded into sshpass.