SSHPass is a small command-line utility that lets you pass a password directly to an SSH connection, which means no interactive password prompt. Useful when you’re writing scripts that need to connect to remote machines without manual intervention.
A word of warning before you go ahead: SSHPass is not secure. The password gets passed as a command-line argument, which means it can show up in process listings and shell history. It’s fine for personal automation on your own machines, but don’t use it in shared environments or anything that touches production systems.
Ubuntu
Ubuntu ships sshpass in its default repositories, so installation is one command:
sudo apt-get install sshpass
That’s all there is to it.
macOS
There’s no official macOS package for sshpass, so you’ll need to grab it through Homebrew. The standard Homebrew repository doesn’t include it, but someone maintains an alternative formula:
brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
You’ll need Xcode and the command-line tools installed first, but if you’ve done any development on a Mac you probably already have those.
Using It
Once installed, the basic usage looks like this:
sshpass -p 'your_password' ssh user@hostname
Or if you’d rather not have the password sitting in your shell history:
sshpass -f /path/to/password_file ssh user@hostname
The password file approach is slightly better, though it still isn’t ideal from a security standpoint. For anything serious, SSH keys are the way to go.