sshpass 使用方法-命令行使用密码远程连接或拉取文件

Apply:命令行使用密码远程连接或拉取文件!

Usage:

-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) 参数为此次连接的密码,极不安全(.bash_history)   -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

实例1:远程连接某主机

连接一个允许root用户以ssh服务登录的主机host666(密码为mypass,ssh非默认端口,端口号为12345)

sshpass -p mypass ssh -p 12345 root@host666

实例2:从密码文件/passwd.txt取密码以root用户连接主机myhost

sshpass -f passwd.txt ssh root@myhost

实例3:上传文件到远程主机

sshpass -p passwd scp ./src/mysrc  root@myhost:/usr/bin/

实例4:从远程主机myhost下载文件/home/myself下所有文件到当前目录的temp目录

sshpass -p passwd scp root@myhost:/home/myself/* ./temp/

Download and Install:

Ubuntu:

apt-get install sshpass

centos:

wget http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz

tar xvzf sshpass-1.05.tar.gz 
 cd sshpass-1.05
 ./configure 
 make 
 make install

(0)

相关推荐