sshpass,一个简单、轻量级命令行工具,提供非交互式密码验证。用于非交互的 ssh 密码验证。可以在命令行直接使用密码来进行远程连接和远程拉取文件。
使用前提
不支持对于未连接过的主机 (主要问题在于"输入yes进行确认")。
语法格式
常用参数
安装sshpass
1
2
3
|
[root@tools ~]# yum install -y epel-release
[root@tools ~]# yum install -y sshpass
[root@tools ~]# sshpass -V
|
基本使用方法
1
|
[root@tools ~]# sshpass -p "password" ssh username@host_ip
|
当远程主机端口非默认22端口的场景
1
|
[root@tools ~]# sshpass -p "password" ssh -p 10022 username@host_ip
|
直接远程连接某台主机
1
|
[root@tools ~]# sshpass -p xxx ssh root@host_ip
|
本地执行远程机器的命令
1
|
[root@tools ~]# sshpass -p xxx ssh root@host_ip "ethtool eth0"
|
远程连接指定ssh的端口
1
|
[root@tools ~]# sshpass -p 123456 ssh -p 1000 root@host_ip
|
从密码文件读取文件内容作为密码去远程连接主机
1
|
[root@tools ~]# sshpass -f xxx.txt ssh root@host_ip
|
从远程主机上拉取文件到本地
1
|
[root@tools ~]# sshpass -p '123456' scp root@host_ip:/home/test/123.log ./tmp/
|