使用sshpass的场景

在MacOS下使用ansible命令(inventory文件中使用了密码验证的方式)或者使用iTerm2来完成自动密码填充等场景会使用到sshpass。

比如下面的样例:Inventory文件中使用了ansible_ssh_pass选项

stephens-New-MacBook-Pro:ansible stephen$ cat test.hosts
10.10.66.66 ansible_port=22 ansible_user=root ansible_ssh_pass=test666
stephens-New-MacBook-Pro:ansible stephen$

使用ansible命令会失败,提示缺少sshpass

stephens-New-MacBook-Pro:ansible stephen$ ansible all -i test.hosts  -m ping
10.10.66.66 | FAILED! => {
"failed": true,
"msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"
}
stephens-New-MacBook-Pro:ansible stephen$

安装sshpass及各种常见小问题处理

直接brew install会提示不安全,被拒绝,brew install --force强制安装也不行

stephens-New-MacBook-Pro:ansible stephen$ brew install sshpass -f
Updating Homebrew...
Error: No available formula with the name "sshpass"
We won't add sshpass because it makes it too easy for novice SSH users to
ruin SSH's security.
stephens-New-MacBook-Pro:ansible stephen$

可以通过下面的命令进行安装

brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb

sshpass.rb文件内容

require 'formula'

class Sshpass < Formula
url 'http://sourceforge.net/projects/sshpass/files/sshpass/1.06/sshpass-1.06.tar.gz'
homepage 'http://sourceforge.net/projects/sshpass'
sha256 'c6324fcee608b99a58f9870157dfa754837f8c48be3df0f5e2f3accf145dee60' def install
system "./configure", "--disable-debug", "--disable-dependency-tracking",
"--prefix=#{prefix}"
system "make install"
end def test
system "sshpass"
end
end

如果(因为众所周知的网络原因)通过brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb的方式不能正常工作,可以将上面rubby脚本sshpass.rb的内容拷贝到本地执行brew install sshpass.rb

再次尝试安装提示缺少xcode-select命令行工具,可以通过xcode-select --install进行安装

stephens-New-MacBook-Pro:ansible stephen$ brew install sshpass.rb
Error: Xcode alone is not sufficient on Mojave.
Install the Command Line Tools:
xcode-select --install stephens-New-MacBook-Pro:ansible stephen$ xcode-select --install
xcode-select: note: install requested for command line developer tools
stephens-New-MacBook-Pro:ansible stephen$

安装完xcode-select之后重新执行brew install命令,sshpass安装成功。

stephens-New-MacBook-Pro:ansible stephen$ brew install sshpass.rb
Updating Homebrew...
==> Downloading http://sourceforge.net/projects/sshpass/files/sshpass/1.06/sshpass-1.06.tar.gz
==> Downloading from https://jaist.dl.sourceforge.net/project/sshpass/sshpass/1.06/sshpass-1.06.tar.g
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/sshpass/1.06
==> make install

最新文章

  1. 学习shell中遇到的一些基础问题总结
  2. C#函数式程序设计之用闭包封装数据
  3. Bulk Insert &amp; BCP执行效率对比
  4. 实用项目管理前台框架:EasyUI,ExtJs
  5. jQuery 源码解析二:jQuery.fn.extend=jQuery.extend 方法探究
  6. 搜索引擎爬虫蜘蛛的USERAGENT大全
  7. MD5处理图片加密算法
  8. tp框架知识 之(链接数据库和操作数据)
  9. H5 表单元素
  10. HighCharts之2D对数饼图
  11. Ext.grid.panel 改变某一行的字体颜色
  12. [JLOI2015]骗我呢
  13. Silverlight中使用MVVM(1)--基础
  14. k8s 隔离context+namespace
  15. [整理]CSS3 滤镜
  16. [USACO14MAR]破坏Sabotage
  17. Delphi实例分析:远程传输数据和文件
  18. vue-compile概述
  19. 【转】Android:No implementation found for native
  20. Linux对包管理阐述

热门文章

  1. iptables添加、删除端口
  2. leetcode 27. 移除元素(python)
  3. seleniumIDE回放找不到页面元素
  4. Html/CSS 初步介绍html和css部分重要标签
  5. C# Setting.settings . 用法 2 使用配置文件(.settings、.config)存储应用程序配置
  6. c++ 加载资源文件
  7. Servlet 响应 响应相关与重定向 请求 获取表单数据2种方法
  8. 可持久化并查集 by zky
  9. 【DSP开发】【Linux开发】基于ARM+DSP进行应用开发
  10. Linux 项目上线流程