SSHPass: SSH Login With Password – Command Line

A password-based authentication is often a default way to connect to a remote host over SSH.

But as it requires a user to enter a password manually, this creates some complicity if you need to automate the SSH login.

This note shows how to login over SSH by passing the password as a parameter on a command-line using the sshpass command.

Cool Tip: Log in to a remote Linux server without entering password! Set up password-less SSH login! Read more →

SSH Login With Password

Install the sshpass tool, that permits to set the SSH password on the command-line:

# Debian/Ubuntu/Linux Mint
$ sudo apt-get install sshpass
# RedHat/CentOS
$ sudo yum install epel-release
$ sudo yum install sshpass
# macOS
$ brew install hudochenkov/sshpass/sshpass

To login to a host over SSH by passing the plain-text password as a parameter, use the sshpass command as follows:

$ sshpass -p <password> ssh <user>@<hostname>
- example -
$ sshpass -p P@$$w0rd ssh root@

To execute a command over SSH without being prompted for a password:

$ sshpass -p <password> ssh <user>@<hostname> "<command(s)>"
- example -
$ sshpass -p P@$$w0rd ssh root@ "whoami; hostname"
- sample output -

Leave a Reply