sshpass的使用方法

时间:2023-03-09 07:44:24
sshpass的使用方法

author:headsen  chen

date : 2017-11-29  15:46:39

notice:created  by  headsen chen himself   and not allowed to copy,or  will done by low.

应用范围:可以在命令行直接使用密码来进行远程连接和远程拉取文件。

实例1:直接远程连接某台主机:

命令:sshpass -p xxx ssh root@192.168.11.11

sshpass的使用方法

实例2:远程连接指定ssh的端口:

命令:sshpass -p 123456 ssh -p 1000 root@192.168.11.11         (当远程主机不是默认的22端口时候)

sshpass的使用方法

实例3:从密码文件读取文件内容作为密码去远程连接主机

命令:sshpass -f xxx.txt  ssh root@192.168.11.11

sshpass的使用方法

实例4:从远程主机上拉取文件到本地

命令: sshpass -p '123456' scp root@host_ip:/home/test/t ./tmp/

sshpass的使用方法

补:

ssh的配置文件位置:vim /etc/ssh/sshd_config

sshpass的使用方法

去掉#,修改端口号。

sshpass的安装:

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.tar.gz

./configure 
 make 
 make install