Ansible: To use the ssh connection type with passwords, you must install the sshpass program

This guide will show you how to fix the following error when running your Ansible Playbook: “to use the ssh connection type with passwords, you must install the sshpass program”.

The error may look something like this:

TASK [Gathering Facts] ******************************************************************************************************************************************************************
fatal: [albus.local]: FAILED! => {"msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"}

What is sshpass?

sshpass is a command-line tool that allows you to do non-interactive ssh login.

So how is sshpass different for ssh? Well, ssh uses direct TTY access to ensure that an interactive keyboard user issues the password. However, sshpass runs ssh in a dedicated TTY, tricking ssh into thinking that the password is from an interactive user.

It would be best if you did not use sshpass on a production server. The reason is that sshpass reveals the password to all system users on the command line using the “ps” command.

According to the sshpass man page:

Users of sshpass are encouraged to use one of the other password passing techniques, which are all more secure. In particular, people writing programs that are meant to communicate the password programatically are encouraged to use an anonymous pipe and pass the pipe's reading end to sshpass using the -d option.

So, how do you fix this Ansible error?

Ansible requires sshpass to be able to run ssh commands without prompting passwords. Therefore, you have to install the sshpass package on your Ansible control machine to resolve this error.

Ansible will not prompt for passwords when you:

  • Remove the “ask_pass=True” line in ansible.cfg file.
  • Add the “ansible_ssh_pass=<mypass>” line in the inventory file.

The settings mentioned above will require Ansible to use sshpass. The reason is that Ansible will not prompt you to enter the password manually.

How to install sshpass for Ansible to support ssh passwords?

You can install sshpass on Debian/Ubuntu and its derivatives using the apt-get command:

sudo apt install sshpass

Alternatively, you can install sshpass on RedHat/CentOS using the yum command:

yum install epel-release
yum install sshpass

Wrapping up

You should now be able to run your Ansible Playbook without the “to use the ssh connection type with passwords, you must install the sshpass program” error.

You may also be interested in



About the Authors

Anto's editorial team loves the cloud as much as you! Each member of Anto's editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic! Contact Anto Online if you want to contribute.

Support the Cause

Support Anto Online and buy us a coffee. Anything is possible with coffee and code.

Buy me a coffee



About Anto Online

Having started his career in 1999 as a Desktop Support Engineer, Anto soon changed paths and became a developer. After several years of development experience, he transitioned into a consultant. As an enterprise application consultant for a leading SaaS software provider, Anto specializes in AWS's serverless technologies. By day, Anto focuses on helping customers leverage the power of serverless technologies. By night, he indulges his passion for cloud computing by playing with Python and trying out things that are currently beyond the scope of his work. Sometimes Anto needs help as there are not enough hours at night. So Anto relies on a team of fellow Cloud enthusiasts to help him out. Each one is a Cloud expert in their own right, and Anto takes great pride in helping them learn and grow.

View all posts by Anto Online →

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.