There is a slight variant of a way described in the blog on how to use sshpass which can be found here. Given that you have a gpg encrypted password (how ot do this is described in the blog) file you could do something like this: sshpass -p $ (echo $ (gpg -d -q.sshpasswd.gpg)) ssh yourdesination.xyz.

Sshpass

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.

  • In my case, I have a situation that I'm trying to send a file via SCP using sshpass but I can't. I need to use a script with a password but the easiest way doesn't work on the hostName2 I have no possibility to see configuration sshdconfig etc. And send ssh-copy-id, I need use 'myPass'.
  • Feb 09, 2014 To get past the sshpass error, you can install sshpass from source code with the following steps: Install Xcode from the App Store. Once Xcode is installed, download and install the Command Line Tools by opening Xcode opening Xcode’s Preferences clicking the Downloads tab clicking Command Line Tools and finally clicking the Install.
  • How to automatically ssh login with passwords using sshpass: Another option to connect through ssh with automatic password login is the sshpass tool. Although you can install sshpass using apt, yum, or any other packages manager, it is recommended to download its last version and install from sources.
  • Mac OS X Lion and sshpass. Using the builtin dialog under OSX to unlock an SSH key. Terminal won't ask for passphrase and not stored in keychain.
Osx

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.

Sshpass Osx Ansible

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.

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.

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.

While bootstraping a new Rackspace Public Cloud Server with Ansible 1.4.4 on OS X Mavericks, I received an error when running ansible-playbook bootstrap.yml --user root --ask-pass.

The error encountered was:

Ansible uses sshpass when logging in to a server via SSH using a password. Apparently, Apple removed sshpass and merged its functionality into the ssh, scp, and ssh-add commands.

Sshpass Osx

For security reasons, you should have Ansible logging in to servers using SSH keys, but for new servers it is simpler to initially log in with a password, have Ansible setup your users and SSH keys, then have subsequent logins use SSH keys.

To get past the sshpass error, you can install sshpass from source code with the following steps:

Sshpass Linux Install

  1. Install Xcode from the App Store.

  2. Once Xcode is installed, download and install the Command Line Tools by opening Xcode > opening Xcode’s Preferences > clicking the Downloads tab > clicking Command Line Tools > and finally clicking the Install button.

  3. Once the Command Line Tools are installed, download and un-tar the sshpass source code:

  4. Configure, make, and install the sshpass binary:

Now, re-running ansible-playbook bootstrap.yml --user root --ask-pass will work without a problem.

Sshpass Linux

The steps in this post are no longer necessary if you are running Ansible 1.9.2 or newer. This issue was probably fixed in a version prior to Ansible 1.9.2, but I don’t know which version.