乐趣区

关于macos:macOS-安装-sshpass

前言

sshpass 是 ansible 明码输出的必要条件,在 Linux 中应用 yum install sshpass 或者 apt-get install sshpass 都能够轻松装置,但在 macOS 新版本中因为平安起因无奈间接应用brew install sshpass,须要采纳其它平安的方法绕过。

更新历史

2020 年 10 月 13 日 – 初稿

浏览原文 – https://wsgzao.github.io/post…


应用 sshpass 的场景

在 macOS 下应用 ansible 命令 (inventory 文件中应用了明码验证的形式) 或者应用 iTerm2 来实现主动明码填充等场景会应用到 sshpass。

比方上面的样例:Inventory 文件中应用了 ansible_ssh_pass 选项

# 编辑 inventory
cat hosts
10.10.66.66 ansible_port=22 ansible_user=root ansible_ssh_pass=test666

# 应用 ansible 命令会失败,提醒短少 sshpass
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"
}

装置 sshpass 及各种常见小问题解决

间接 brew install 会提醒不平安,被回绝,brew install --force强制装置也不行

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.

能够通过上面的命令进行装置

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

Error: Calling Non-checksummed download of sshpass formula file from an arbitrary URL is disabled! Use 'brew extract' or 'brew create' and 'brew tap-new' to create a formula file in a tap on GitHub instead.

# 呈现上述报错能够下载至本地再次执行装置
wget https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
brew install 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 进行装置

brew install sshpass.rb
Error: Xcode alone is not sufficient on Mojave.
Install the Command Line Tools:
  xcode-select --install

xcode-select --install
xcode-select: note: install requested for command line developer tools

装置完 xcode-select 之后从新执行 brew install 命令,sshpass装置胜利。

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
????  /usr/local/Cellar/sshpass/1.06: 9 files, 41.6KB, built in 33 seconds
退出移动版