Installing sshpass On OSX Mavericks

16th February 2014

When setting up a server for the first time with Ansible you will need to pass ssh credentials to Ansible directly to set up ssh keys. This is done by the use of the sshpass program which allows Ansible to pass your user credentials directly to ssh in order to open a connection to the server. The sshpass program is easily installed on Linux systems with the apt or yum package managers, but on OSX you will need to install it manually.

In order to install command line software on OSX you will need some of the command line tools bundled with Xcode. Xcode and the command line tools are free programs from Apple and is available on the Appstore. Once Xcode is installed you will need to open it and install the command line tools. You can do this by going to Preferences > Downloads > Command Line Tools and clicking on the Install button. Once everything is installed and setup you can continue with the installation of sshpass.

The sshpass program is an open source project, currently available on sourceforge. You can either download the latest version manually and or you can use the following command will download the sshpass tar from sourceforge, and unzip it. curl -O -L http://downloads.sourceforge.net/project/sshpass/sshpass/1.05/sshpass-1.05.tar.gz && tar xvzf sshpass-1.05.tar.gz

This will create a directory called 'sshpass-1.05', open this directory in your terminal and run the following commands. This will configure, compile and install the sshpass program.

  1. ./configure
  2. make
  3. sudo make install

Once complete you can run sshpass with the -V flag to see if the install has taken and also to view the current version installed.

  1. $ sshpass -V
  2. sshpass 1.05 (C) 2006-2011 Lingnu Open Source Consulting Ltd.
  3. This program is free software, and can be distributed under the terms of the GPL
  4. See the COPYING file for more information.

I should note that it is poor security practice to rely on the sshpass to interface with servers, even through Ansible. This is because you will be placing ssh credentials into the command line or even within your codebase.

Comments

Permalink
Haha, I just tried to install it via Homebrew:
  1. $ brew search sshpass
  2. We won't add sshpass because it makes it too easy for novice SSH users to
  3. ruin SSH's security.

Ron (Mon, 02/17/2014 - 02:43)

Permalink
Hi Phil, Thanks for putting this together! I'm provisioning a lot of new servers and I've got to log into 1000+ servers and this will do the trick for my scripts. I had hoped for a DMG but this was just as simple - Thanks for putting this post together! Much appreciated, Jay

Jay (Fri, 09/05/2014 - 17:01)

Permalink
Thanks!

Richard Clayton (Fri, 03/27/2015 - 16:47)

Permalink
  1. $ brew install https://raw.github.com/eugeneoden/homebrew/eca9de1/Library/Formula/sshpass.rb
  2. ######################################################################## 100.0%
  3. ==> Downloading http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz
  4. ######################################################################## 100.0%
  5. Error: MD5 support has been dropped for security reasons.
  6. Please switch this formula to SHA256.

Eduard (Thu, 04/09/2015 - 18:58)

Permalink
Same error

zq (Thu, 04/23/2015 - 03:02)

Permalink
How did you solve it?

philipnorton42 (Thu, 04/23/2015 - 09:27)

Permalink
On Yoshemite
  1. $ brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
  2. ######################################################################## 100.0%
  3. ==> Downloading http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz
  4. Already downloaded: /Library/Caches/Homebrew/sshpass-1.05.tar.gz
  5. Error: SHA256 mismatch
  6. Expected: c3f78752a68a0c3f62efb3332cceea0c8a1f04f7cf6b46e00ec0c3000bc8483e
  7. Actual: 96ca20a16a86083b1eb666fecbfa5b3f9eb7317ec9e6fcfcae5a91d96777b767
  8. Archive: /Library/Caches/Homebrew/sshpass-1.05.tar.gz
  9. To retry an incomplete download, remove the file above.

Askar (Thu, 06/04/2015 - 06:16)

Permalink
It works, thanks

Yann de Champlain (Wed, 09/02/2015 - 14:24)

Permalink
Hi, i have upgraded the Mac to 10.11. When i try to install the sshpass using above commands, i get the following message after the make install command. I see that sshpass is not installed. Any idea what is missing on new Mac ? Please note that I have installed the x-code command line tools. /usr/bin/install -c -m 644 sshpass.1 '/usr/local/share/man/man1'ocal/share/man/man1"

Jagadeesh (Tue, 11/17/2015 - 12:26)

Permalink
Thanks for article, this is work's for me.

Dika Fernando (Tue, 11/29/2016 - 18:10)

Add new comment

The content of this field is kept private and will not be shown publicly.