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.

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

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@192.168.1.100 "whoami; hostname"
- sample output -
root
ubuntu-2004
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Start a GUI Application on a Remote Computer using SSH

This article describes how to log into the remote computer (server) using SSH and run a GUI...

SSH Login Slow — Removing Delay

Problem: When I’m trying to log into the remote server via SSH, after I enter the UserName, it...

Signing Failed: Agent Refused Operation [SOLVED]

While attempting to connect to some server over SSH, you may get the error as follows:...

SSH Fingerprint: Get Fingerprint of SSH RSA Key

The fingerprint is a unique sequence of letters and numbers used to identify the SSH RSA key. It...

SSH: Create Public Key from Private

Usually a public SSH key is generated at the same time as a private key. Unlike a private SSH...