Homebrewでインストールが非推奨!?になったsshpassはソースコードビルドでインストールしよう


sshパスワード認証に用いるパスワードを引数渡しで利用出来るsshpassコマンドはLinuxの場合はパッケージマネージャーから簡単にインストール出来ますが,Macの場合は標準ではHomebrewからインストール出来ません1。故に従来は参考の様な方法でインストールを行っていました。しかし,最近はbrew doctorコマンド実行時に以下の様な警告が出る様になりました。どうやらHomebrewによるインストール対象アプリケーションのリポジトリ一覧からsshpassが削除されてしまっている様です。

Warning: Some installed kegs have no formulae!
This means they were either deleted or installed with `brew diy`.
You should find replacements for the following formulae:
  sshpass

このままでも害は無いのですが,どうも気持ち悪いということで,参考に記載されているソースビルドによるインストールを実施します。
この方法を用いれば,上記の警告は出ません。

ソースファイルのダウンロード

以下のコマンドを実行し,ビルドするsshpassのソースファイルアーカイブ(tar.gzファイル)をダウンロードします。どうやら北陸先端科学技術大学院大学が管理しているミラーサイトの様です。

ソースファイルアーカイブのダウンロード
wget https://jaist.dl.sourceforge.net/project/sshpass/sshpass/1.06/sshpass-1.06.tar.gz

実行結果

$ wget https://jaist.dl.sourceforge.net/project/sshpass/sshpass/1.06/sshpass-1.06.tar.gz
--2020-11-30 15:14:01--  https://jaist.dl.sourceforge.net/project/sshpass/sshpass/1.06/sshpass-1.06.tar.gz
jaist.dl.sourceforge.net (jaist.dl.sourceforge.net) をDNSに問いあわせています... 150.65.7.130
jaist.dl.sourceforge.net (jaist.dl.sourceforge.net)|150.65.7.130|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 112205 (110K) [application/x-gzip]
`sshpass-1.06.tar.gz' に保存中

sshpass-1.06.tar.gz                     100%[=============================================================================>] 109.58K   416KB/s 時間 0.3s     

2020-11-30 15:14:02 (416 KB/s) - `sshpass-1.06.tar.gz' へ保存完了 [112205/112205]

アーカイブファイルの解凍

tar.gzファイルを解凍します。以下のコマンドで実行出来ます。

tar xvf sshpass-1.06.tar.gz

実行結果

$ tar xvf sshpass-1.06.tar.gz 
x sshpass-1.06/
x sshpass-1.06/main.c
x sshpass-1.06/install-sh
x sshpass-1.06/AUTHORS
x sshpass-1.06/config.h.in
x sshpass-1.06/depcomp
x sshpass-1.06/aclocal.m4
x sshpass-1.06/configure
x sshpass-1.06/NEWS
x sshpass-1.06/compile
x sshpass-1.06/ChangeLog
x sshpass-1.06/INSTALL
x sshpass-1.06/Makefile.am
x sshpass-1.06/sshpass.1
x sshpass-1.06/COPYING
x sshpass-1.06/README
x sshpass-1.06/Makefile.in
x sshpass-1.06/configure.ac
x sshpass-1.06/missing

ビルドの実行及びインストール

ソースファイルをビルドし,sshpassをインストールします。

cd sshpass-1.06/
mkdir build && cd build
../configure

macOS 11.1 Big Surにおいては標準gcc(clang)でのみコンパイルが可能(2020/12/17現在)

実行結果

$ ../configure 
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking for ANSI C header files... (cached) yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking sys/ioctl.h usability... yes
checking sys/ioctl.h presence... yes
checking for sys/ioctl.h... yes
checking for unistd.h... (cached) yes
checking termios.h usability... yes
checking termios.h presence... yes
checking for termios.h... yes
checking for an ANSI C-conforming const... yes
checking for pid_t... yes
checking for ssize_t... yes
checking vfork.h usability... no
checking vfork.h presence... no
checking for vfork.h... no
checking for fork... yes
checking for vfork... yes
checking for working fork... yes
checking for working vfork... (cached) yes
checking whether gcc needs -traditional... no
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... yes
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking sys/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking types of arguments for select... int,fd_set *,struct timeval *
checking return type of signal handlers... void
checking for select... yes
checking for posix_openpt... yes
checking for strdup... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands

make

実行結果
$ make
/Library/Developer/CommandLineTools/usr/bin/make  all-am
gcc -DHAVE_CONFIG_H -I. -I..   -I/usr/local/opt/openjdk/include  -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o ../main.c
mv -f .deps/main.Tpo .deps/main.Po
gcc  -g -O2  -L/usr/local/opt/sqlite/lib -o sshpass main.o

sudo make install

実行結果

$ sudo make install 
 ../install-sh -c -d '/usr/local/bin'
  /usr/bin/install -c sshpass '/usr/local/bin'
 ../install-sh -c -d '/usr/local/share/man/man1'
 /usr/bin/install -c -m 644 ../sshpass.1 '/usr/local/share/man/man1'

$ sshpass -V
sshpass 1.06
(C) 2006-2011 Lingnu Open Source Consulting Ltd.
(C) 2015-2016 Shachar Shemesh
This program is free software, and can be distributed under the terms of the GPL
See the COPYING file for more information.

Using "assword" as the default password prompt indicator.

アンインストール

アンインストールする場合はbuildディレクトリ配下で以下のコマンドを実行します。

sudo make uninstall

Reference


  1. セキュリティ上パスワードを引数渡しをするのは好ましくないという理由は納得出来ます。しかしちょっと実験環境として利用するVMにいちいち公開鍵を設定するのは面倒ですし,パスワードを毎回入力するのも煩雑です。