sshpass 使用方法
首先下载sshpass并且安装
$ tar -zxvf sshpass-1.06.tar.gz
$ cd sshpass-1.06
$ ./configure --prefix=/usr/local/sshpass #指定安装目录
$ make
$ make install
[root@qinhan ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.43.105 netmask 255.255.255.0 broadcast 172.16.43.255
inet6 fe80::20c:29ff:fe22:1f4f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:22:1f:4f txqueuelen 1000 (Ethernet)
RX packets 2 bytes 120 (120.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 768 (768.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eno33554984: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.27.100 netmask 255.255.255.0 broadcast 192.168.27.255
inet6 fe80::20c:29ff:fe22:1f59 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:22:1f:59 txqueuelen 1000 (Ethernet)
RX packets 12683 bytes 8934971 (8.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7687 bytes 985668 (962.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 1301 bytes 132447 (129.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1301 bytes 132447 (129.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@qinhan ~]# sshpass -p root ssh root@192.168.27.3
Last login: Fri Jan 19 10:24:38 2018 from node2.magedu.com
[root@node1 ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.43.102 netmask 255.255.255.0 broadcast 172.16.43.255
inet6 fe80::20c:29ff:fe53:14fc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:53:14:fc txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 768 (768.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eno33554960: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.27.3 netmask 255.255.255.0 broadcast 192.168.27.255
inet6 fe80::20c:29ff:fe53:1406 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:53:14:06 txqueuelen 1000 (Ethernet)
RX packets 1604 bytes 166368 (162.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 610 bytes 137655 (134.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 3588 bytes 310356 (303.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3588 bytes 310356 (303.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@node1 ~]#
问题来了如果 删除~/.ssh/known_hosts,我们在使用 sshpass -p root ssh root@192.168.27.3 可以发现没有登陆到192.168.27.3服务器上,
sshpass -p root ssh root@192.168.27.3 -o "StrictHostKeyChecking no" 才能登陆到192.168.27.3服务器上
[root@qinhan ~]# cat ~/.ssh/known_hosts
node2,192.168.27.101 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEkmmdQBm1c0ZHKFPQqhMQvKe+g6sSD5HwYGsZapCJRUmWoyQmvI0iIax1OEMwTy+XzijD7OcQ6t8cXCRKxXva8=
192.168.27.3 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBImdbfgGnbnBPlUNTFs3UQXCVX+xq7LdjrSwB82587hmjWCA0IhYmGFSehvplOdcrlKU8bvEfIxFcZEnCvSUaLM=
node3 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBImdbfgGnbnBPlUNTFs3UQXCVX+xq7LdjrSwB82587hmjWCA0IhYmGFSehvplOdcrlKU8bvEfIxFcZEnCvSUaLM=
node1 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBImdbfgGnbnBPlUNTFs3UQXCVX+xq7LdjrSwB82587hmjWCA0IhYmGFSehvplOdcrlKU8bvEfIxFcZEnCvSUaLM=
[root@qinhan ~]# rm ~/.ssh/known_hosts
rm: remove regular file ‘/root/.ssh/known_hosts’? y
[root@qinhan ~]#
[root@qinhan ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.43.105 netmask 255.255.255.0 broadcast 172.16.43.255
inet6 fe80::20c:29ff:fe22:1f4f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:22:1f:4f txqueuelen 1000 (Ethernet)
RX packets 2 bytes 120 (120.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 768 (768.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eno33554984: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.27.100 netmask 255.255.255.0 broadcast 192.168.27.255
inet6 fe80::20c:29ff:fe22:1f59 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:22:1f:59 txqueuelen 1000 (Ethernet)
RX packets 13038 bytes 8972776 (8.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8020 bytes 1029711 (1005.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 1301 bytes 132447 (129.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1301 bytes 132447 (129.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@qinhan ~]# sshpass -p root ssh root@192.168.27.3
[root@qinhan ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.43.105 netmask 255.255.255.0 broadcast 172.16.43.255
inet6 fe80::20c:29ff:fe22:1f4f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:22:1f:4f txqueuelen 1000 (Ethernet)
RX packets 2 bytes 120 (120.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 768 (768.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eno33554984: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.27.100 netmask 255.255.255.0 broadcast 192.168.27.255
inet6 fe80::20c:29ff:fe22:1f59 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:22:1f:59 txqueuelen 1000 (Ethernet)
RX packets 13074 bytes 8977585 (8.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8047 bytes 1038634 (1014.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 1301 bytes 132447 (129.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1301 bytes 132447 (129.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@qinhan ~]#
[root@qinhan ~]# sshpass -p root ssh root@192.168.27.3 -o "StrictHostKeyChecking no"
Warning: Permanently added '192.168.27.3' (ECDSA) to the list of known hosts.
Last login: Fri Jan 19 10:27:32 2018 from node2.magedu.com
[root@node1 ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.43.102 netmask 255.255.255.0 broadcast 172.16.43.255
inet6 fe80::20c:29ff:fe53:14fc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:53:14:fc txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 768 (768.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eno33554960: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.27.3 netmask 255.255.255.0 broadcast 192.168.27.255
inet6 fe80::20c:29ff:fe53:1406 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:53:14:06 txqueuelen 1000 (Ethernet)
RX packets 1788 bytes 186238 (181.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 721 bytes 162387 (158.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 3588 bytes 310356 (303.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3588 bytes 310356 (303.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
sshpass 使用方法的更多相关文章
- linux 执行远程linux上的shell脚本或者命令以及scp 上传文件到ftp--免密码登陆
场景:在linux A 上执行Linux B上的shell脚本和命令 步骤1.设置ssh免登陆 1.SSH无密码登录 # 本地服务器执行(A机器):生成密钥对 ssh-keygen -t dsa -P ...
- javaSE27天复习总结
JAVA学习总结 2 第一天 2 1:计算机概述(了解) 2 (1)计算机 2 (2)计算机硬件 2 (3)计算机软件 2 (4)软件开发(理解) 2 (5) ...
- sshpass的使用方法
author:headsen chen date : 2017-11-29 15:46:39 notice:created by headsen chen himself and not ...
- 集群工具ansible使用方法
ansible简介 ansible是与puppet.saltstack类似的集群管理工具,其优点是仅需要ssh和Python即可使用,而不像puppet.saltstack那样都需要客户端.与pupp ...
- 使用ssh正向连接、反向连接、做socks代理的方法
ssh -L 219.143.16.157:58080:172.21.163.32:8080 用户名@localhost -p 10142 在 219.143.16.157机器执行 将ssh隧 ...
- CentOS下利用sshpass不用手动输入密码远程执行命令
在测试的时候要同时操作多台机器,每次都要挨个去执行几乎相同的命令或者修改一些设置,这样很影响工作效率也很烦,所以就想写一个脚本,远程自动去做这些操作.远程执行命令很简单,但是不能在执行命令加上命 ...
- source install sshpass in aix
1.源码下载: wget https://nchc.dl.sourceforge.net/project/sshpass/sshpass/1.06/sshpass-1.06.tar.gz 2.解压 ...
- [持续交付实践] Jenkins Pipeline 高可用设计方法
前言 这篇写好一段时间了,一直也没发布上来,今天稍微整理下了交下作业,部分内容偷懒引用了一些别人的内容.使用Jenkins做持续集成/持续交付,当业务达到一定规模的时候,Jenkins本身就很容易成为 ...
- 几种方法来实现scp拷贝时无需输入密码
欢迎转载!转载时请注明出处:http://blog.csdn.net/nfer_zhuang/article/details/42646849 前言 我在工作中经常要将一些文件传输到另外一个服务器上, ...
随机推荐
- toString 和new String()区别
public class NewStringTestDemo { public static void main(String[] args) { String s = "你好"; ...
- UEditor (富文本编译器)
下载网址:https://ueditor.baidu.com/website/download.html 开发文档:http://fex.baidu.com/ueditor/
- linux如何复制文件夹和移动文件夹
linux下文件的复制.移动与删除命令为:cp,mv,rm一.文件复制命令cp 命令格式:cp [-adfilprsu] 源文件(source) 目标文件(destination)cp [option ...
- vue中.sync 修饰符
一直以来,都不太明白.sync的用法,归根结底原因在于,没有仔细阅读“.sync修饰符”. 正好,最近在拿一个项目练手,然后使用了elment-ui,然后在用到dialog的时候,属性visible是 ...
- Servlet】(2)有关Servlet实现的几个类:GenericServlet、HttpServlet、ServletConfig、ServletContext
一.GenericServlet 1.所有的成员方法: 1.在javaWeb项目中: 2.web.xml <?xml version="1.0" encoding=" ...
- android 开发 View _14 MotionEvent和事件处理详解,与实践自定义滑动条View
转载https://blog.csdn.net/huaxun66/article/details/52352469 MotionEvent MotionEvent对象是与用户触摸相关的时间序列,该序列 ...
- PHP判断手机、电脑访问
/*判断用户是手机访问还是电脑访问*/$useragent = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/(android|bb\d+|meego). ...
- c#读取文本并生成txt
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- xcode 自动签名原理
签名的核心就是provision profile要与当前的bundle id及本地的私钥相匹配. teamid:每个开发者账号都会对应一个teamid.企业的开发这账号除了对应一个teamid外,下面 ...
- PXC 搭建高可用集群
(1).PXC集群注意事项 1.PXC集群只支持innodb引擎 2.