Software >> OS >> Unix >> Linux >> commands >> sshpass >> What is sshpass and how to use it

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.

If automation is needed when using SSH password authentication, then a sshpass can be used.

How to Install

## For RHEL 7

subscription-manager repos --enable=rhel-7-server-rpms \
                           --enable=rhel-7-server-optional-rpms \
                           --enable=rhel-7-server-extras-rpms \

yum install

yum install sshpass


## Simple example, provide the password to sshpass and let it ssh to your server

sshpass -p MyPassword ssh

## Same example with strict HostKey checking disabled

sshpass -p MyPassword -o StrictHostKeyChecking=no

## using a password file to store the password.  The password should be the first line of the file

echo MyPassword > passwordfile
chmod 0400 passwordfile
sshpass -f passwordfile ssh

## Using a hidden password file and encrypting the password file with GPG
## when invoking the ssh, the .gpg file is decrypted and then piped to sshpass

echo MyPassword > .sshpasswd
gpg -c .sshpasswd
rm .sshpasswd
gpg -d -q .sshpasswd.gpg | sshpass ssh