To use the ‘ssh’ connection type with passwords, you must install the sshpass program

Table of Contents


To fix “to use the the ‘ssh’ connection type with passwords, you must install the sshpass program”, we need to install sshpass package in our ansible control machine.

What is sshpass?

The sshpass utility is designed to run SSH using the keyboard-interactive password authentication mode, but in a non-interactive way.

SSH uses direct TTY access to ensure that the password is indeed issued by an interactive keyboard user. sshpass runs SSH in a dedicated TTY, fooling SSH into thinking it is getting the password from an interactive user.

Install sshpass In Mac OS X

We can install sshpass through source code.

tar zxvf sshpass-1.08.tar.gz
cd sshpass-1.08
sudo make install

% sshpass
Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
-f filename Take password to use from file
-d number Use number as file descriptor for getting password
-p password Provide password as argument (security unwise)
-e Password is passed as env-var “SSHPASS”
With no parameters – password will be taken from stdin
-P prompt Which string should sshpass search for to detect a password prompt
-v Be verbose about what you’re doing
-h Show help (this screen)
-V Print version information
At most one of -f, -d, -p or -e should be used

We can download the latest version sshpass from here

Install sshpass In CentOS 7

yum install sshpass

Install sshpass In Ubuntu

apt install sshpass

sshpass Example

$ sshpass -p ‘MyStrongSSHP@ssword’ ssh username@

we can also put the ssh password to one file like this.

$ echo ‘MyStrongSSHP@ssword’ >ssh_pass_file
$ chmod 0400 ssh_pass_file
$ sshpass -f ssh_pass_file ssh username@

Automate copying of SSH keys to multiple servers

If we have multiple servers and would like to automate copying of SSH public keys to the servers, first create a file with all remote servers.

$ vim /tmp/servers

The use while loop to copy SSH keys:

cat /tmp/servers | while read line; do
sshpass -p ‘SSH_USER_PASSWORD’ ssh-copy-id @$line;


cat /tmp/servers | while read line; do
sshpass -p ‘MySSHP@ssword’ ssh-copy-id username@$line;

Share on facebook
Share on twitter
Share on linkedin
Liquid Web Managed Word Press