sshpass之非交互SSH密码验证

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sshpass之非交互SSH密码验证相关的知识,希望对你有一定的参考价值。

    SSH登陆不能在命令行中指定密码。sshpass用于非交互SSH的密码验证,一般用在shell脚本中,无须手动输入密码。它允许你用 -p 参数指定明文密码,然后直接登录远程服务器,它支持密码从命令行、文件、环境变量中读取。


一、安装sshpass:

1. 通过源码编译安装

# http://sourceforge.net/projects/sshpass/ 下载地址
$ tar -zxvf sshpass-xx.tar.gz
$ ./configure
$ make && make install

2. 通过源服务器安装

$ sudo apt-get install sshpass


二、使用sshpass

1. 登录远程服务器

$ sshpass -p password ssh [email protected]_addr

2. scp上传或下载文件

$ sshpass -p password scp [email protected]_addr:/remote_dir /local_dir
$ sshpass -p password scp /local_dir [email protected]_addr:/remote_dir

3. 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


以上是关于sshpass之非交互SSH密码验证的主要内容,如果未能解决你的问题,请参考以下文章

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

通过 windows 命令提示符使用密码验证执行 ssh

如何使用 Python 的 Paramiko 模块 ssh 进入需要两次密码验证的服务器?

密码学之非对称加密算法

sshpass+expect解决交互式问题

Net::OpenSSH 中的交互模式