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

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.


wget https://sourceforge.net/projects/sshpass/files/latest/download/sshpass/1.08/sshpass-1.08.tar.gz
tar zxvf sshpass-1.08.tar.gz
cd sshpass-1.08
./configure
make
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 https://sourceforge.net/projects/sshpass/.



Install sshpass In CentOS 7

yum install sshpass

Install sshpass In Ubuntu

apt install sshpass

sshpass Example


$ sshpass -p 'MyStrongSSHP@ssword' ssh username@172.20.21.201

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@172.20.21.201


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
10.20.21.200
10.20.21.201
10.20.21.202
10.20.21.203
10.20.21.204

The use while loop to copy SSH keys:

cat /tmp/servers | while read line; do
  sshpass -p 'SSH_USER_PASSWORD' ssh-copy-id <USERNAME>@$line;
done

Example:


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


47 views