sshpass—用于非交互的ssh 密码验证

SSHPASS允许用 -p 参数指定明文密码,然后直接登录远程服务器。 Linux默认不支持sshpass,需要安装。ssh-how-to-login-with-password-provided-from-command-line-use-sshpass-to-run-same-command-to-forest-of-linux-servers

名称

sshpass

安装

Ubuntu

sudo -s

apt-get update

apt-get install -y sshpass

Centos

cd /etc/yum.repos.d/

wget http://download.opensuse.org/repositories/home:Strahlex/CentOS_CentOS-6/home:Strahlex.repo

yum install sshpass

编译安装

wget http://sourceforge.net/projects/sshpass/files/latest/download

tar zxvf sshpass-1.05.tar.gz

cd sshpass-1.05

./configure --prefix=/opt/sshpass

make

make install

语法

sshpass [-f|-d|-p|-e] [-hV] command parameters

参数

  [root@www ~/sshpass-1.05]# 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
 
   -h            Show help (this screen)
   -V            Print version information
   At most one of -f, -d, -p or -e should be used

结合ssh一起使用

sshpass -p "mypassword" ssh -p 22 user@127.0.0.1 

参考

http://www.chenyudong.com/archives/sshpass-ssh-password-parameter-non-interactive-ssh.html

JackSun

JackSun

I'm a coder.

You may also like...