The sshpass command is a non-interactive ssh password authentication command line tool that can assist system administrators in automating SSH logins. This tool is convenient when you need to automate SSH logins, such as in a script, without having to manually enter a password each time. This can help save time and streamline processes, especially when managing multiple servers or devices.
The sshpass command is generally discouraged because it is not regarded as a secure authentication method. This is because the password is passed in cleartext on the command line and saved in the user's shell history file, which other system users with access to the system can potentially view.
The sshpass utility was created to execute SSH using keyboard-interactive password authentication in a non-interactive manner. SSH requires direct TTY access to guarantee that the password is being inputted by an interactive keyboard user. However, sshpass runs SSH and supplies password to ssh prompt in a dedicated TTY, fooling SSH into believing that an interactive user is entering the password.
The password prompt utilized by Secure Shell (SSH), on the other hand, is hardcoded into the sshpass utility.
The sshpass utility has several features that make it useful for automated SSH logins. These include:
The sshpass command takes uses the -p to take the password as an argument and then provides it to the ssh command for authentication. The password can also be read from a file using the -f option followed by the file name.
Syntax
The basic syntax of the sshpass command is as follows:
sshpass [-ffilename|-dnum|-ppassword|-e] [options] command arguments
where: