首先下载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 使用方法的更多相关文章

  1. linux 执行远程linux上的shell脚本或者命令以及scp 上传文件到ftp--免密码登陆

    场景:在linux A 上执行Linux B上的shell脚本和命令 步骤1.设置ssh免登陆 1.SSH无密码登录 # 本地服务器执行(A机器):生成密钥对 ssh-keygen -t dsa -P ...

  2. javaSE27天复习总结

    JAVA学习总结    2 第一天    2 1:计算机概述(了解)    2 (1)计算机    2 (2)计算机硬件    2 (3)计算机软件    2 (4)软件开发(理解)    2 (5) ...

  3. sshpass的使用方法

    author:headsen  chen date : 2017-11-29  15:46:39 notice:created  by  headsen chen himself   and not ...

  4. 集群工具ansible使用方法

    ansible简介 ansible是与puppet.saltstack类似的集群管理工具,其优点是仅需要ssh和Python即可使用,而不像puppet.saltstack那样都需要客户端.与pupp ...

  5. 使用ssh正向连接、反向连接、做socks代理的方法

     ssh -L 219.143.16.157:58080:172.21.163.32:8080 用户名@localhost -p 10142  在 219.143.16.157机器执行   将ssh隧 ...

  6. CentOS下利用sshpass不用手动输入密码远程执行命令

       在测试的时候要同时操作多台机器,每次都要挨个去执行几乎相同的命令或者修改一些设置,这样很影响工作效率也很烦,所以就想写一个脚本,远程自动去做这些操作.远程执行命令很简单,但是不能在执行命令加上命 ...

  7. source install sshpass in aix

    1.源码下载:   wget https://nchc.dl.sourceforge.net/project/sshpass/sshpass/1.06/sshpass-1.06.tar.gz 2.解压 ...

  8. [持续交付实践] Jenkins Pipeline 高可用设计方法

    前言 这篇写好一段时间了,一直也没发布上来,今天稍微整理下了交下作业,部分内容偷懒引用了一些别人的内容.使用Jenkins做持续集成/持续交付,当业务达到一定规模的时候,Jenkins本身就很容易成为 ...

  9. 几种方法来实现scp拷贝时无需输入密码

    欢迎转载!转载时请注明出处:http://blog.csdn.net/nfer_zhuang/article/details/42646849 前言 我在工作中经常要将一些文件传输到另外一个服务器上, ...

随机推荐

  1. AlexNet实践

    注释: CNN使用TF搭建比较简单,就像Hough检测使用CV很简单一样.但是怎么使用CNN去做一些实际操作,或者说怎么使用现有的方法进行慢慢改进,这是一个很大的问题! 直接跟着书本或者视频学习有点膨 ...

  2. 44个Java代码性能优化总结

    https://blog.csdn.net/xiang__liu/article/details/79321639 ---稍后有时间整理

  3. JS HTML倒计时 进入页面

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. python_05 可变类型与不可变类型、集合、字符串格式化

    可变数据类型与不可变数据类型: 1.可变:列表,字典 2.不可变:字符串,数字,元组 访问顺序: 1.顺序访问:字符串,列表,元组 2.映射:字典 集合 由不同元素组成的集合,集合中是一组无序排列的可 ...

  5. BASIC GIT WORKFLOW

    BASIC GIT WORKFLOW Generalizations You have now been introduced to the fundamental Git workflow. You ...

  6. 搭建mxnet-gpu docker的pyhon remote kernel

    起因 最近看mxnet的东西,打算给实验室的机器装一个mxnet的环境,无奈实验室里面机器已经装了tensorflow,运行了好久了,环境比较老.而mxnet可是支持最新的cuda9.1和cudnn7 ...

  7. php 计算 距离

    function getdistance($lng1,$lat1,$lng2,$lat2){ //将角度转为狐度 $radLat1=deg2rad($lat1);//deg2rad()函数将角度转换为 ...

  8. PHPStorm 2018 的安装 汉化 与使用

    下载地址 和安装方法 链接:https://pan.baidu.com/s/1FT8aZoQajw044qlNXkRPfg 提取码:z4sx 配置与使用方法 https://blog.csdn.net ...

  9. 在ASP.NET MVC中使用UEditor无法提交的解决办法

    很简单的一个ajax提交,却怎么都不成功 $.ajax({ type: "POST", url: "/mms/riskmanage/commitreply", ...

  10. 43 【redis cluster】

    有两篇文章不错,可以看下: 1,初步理解redis cluster:https://blog.csdn.net/dc_726/article/details/48552531 2,仔细理解redis ...