Operations 3 min read

Master Non-Interactive SSH with sshpass: Quick Password-less Automation

sshpass enables non-interactive SSH sessions by allowing passwords to be supplied directly via command line, password files, or environment variables, simplifying automated remote operations; this guide explains its usage, installation, and common command examples for Linux administrators.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Master Non-Interactive SSH with sshpass: Quick Password-less Automation

ssh is a common Linux service that requires interactive password entry, which complicates automation in shell scripts. While password‑less SSH can be configured, it is cumbersome; an alternative is using expect to script password input. A simpler tool is sshpass , which allows non‑interactive SSH by specifying the password directly.

Usage Examples

(1) Specify password on the command line

./sshpass -p password ssh -o StrictHostKeyChecking=no [email protected] -p port "ls"

Use -o StrictHostKeyChecking=no to skip the first‑time host key check. The -p port option sets the remote SSH port; it can be omitted for the default port.

Remote copy example:

./sshpass -p password scp -P port 15.28.16.3:/root/test.txt .

(2) Use a password file

echo "password" > ssh_passwd
./sshpass -f ssh_passwd ssh -o [email protected] "ls"

(3) Read password from an environment variable

export SSHPASS="password"
./sshpass -e ssh -o [email protected] "ls"

Installing sshpass

Download URL: http://sourceforge.net/projects/sshpass/ Installation steps:

tar zxvf sshpass-1.05.tar.gz
cd sshpass-1.05
./configure --prefix=/usr/local/sshpass
make
make install

After installation, the sshpass command is located in /usr/local/sshpass/bin and can be executed directly.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

AutomationShell scriptingSSHsshpass
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.