SSH登录不能在命令行中指定密码。sshpass用于非交互SSH的密码验证,通常用在shell脚本中,无须手动输入密码。它容许你用 -p 参数指定明文密码,而后直接登陆远程服务器,它支持密码从命令行、文件、环境变量中读取。python
1、安装sshpass:shell
1. 经过源码编译安装服务器
# http://sourceforge.net/projects/sshpass/ 下载地址 $ tar -zxvf sshpass-xx.tar.gz $ ./configure $ make && make install
2. 经过源服务器安装
ssh
$ sudo apt-get install sshpass
2、使用sshpasside
1. 登陆远程服务器
this
$ sshpass -p password ssh username@ip_addr
2. scp上传或下载文件.net
$ sshpass -p password scp username@ip_addr:/remote_dir /local_dir $ sshpass -p password scp /local_dir username@ip_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