• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Mister PKI

SSL Certificates * SSL Tools * Certificate Decoder

  • PKI Training
  • OpenSSL
  • Keytool
  • PKI Tools
    • Apereo CAS
    • SAML
    • OpenID Connect
  • Get expert help

sshpass ssh password authentication automation

August 30, 2024 by Mister PKI Leave a Comment

If you are wondering how to automatically authenticate to a linux server with ssh and password authentication, this article is for you. sshpass is for ssh password authentication automation.

SSH password authentication is primarily used for keyboard-interactive use cases. sshpass gives you the option to run ssh with password authentication in a non-interactive mode. Using an SSH password requires manual intervention when used in a shell script and in many cases this is undesirable, especially when the script needs to be automated. Additionally, entering the SSH password each time you connect can be tedious. sshpass is the utility to workaround these issues.

This option is in our opinion inferior to using ssh public key authentication. If your environment requires password authentication then sshpass may be a suitable option with notable security risks. Namely, if supplying the password in the sshpass command then the passord will be visible in plain text in history. If the password is stored in a file, file permissions should be locked down to only the user(s) needing to access it. If the password is stored in an environment variable, any user with visibility into the environment variable can view it. These shortcomings should be considered before using sshpass.

sshpass Linux Install

While sshpass comes already installed on many OS’s, you can install it with the following commands if needed.

Installing sshpass on Ubuntu

sudo apt-get install sshpass

Installing sshpass on Redhat

sudo dnf install sshpass

sshpass Examples

sshpass with password

sshpass -p "password" ssh <user>@<host>

sshpass with password file

Where pass_file is the file containing the password. It’s permissions should be 0400.

sshpass -f pass_file ssh <user>@<host>

sshpass with environment variable

In this example the environment variable SSHPASS must be set.

sshpass -e ssh <user>@<host>

sshpass with rsync

rsync --rsh='sshpass -p <password> ssh -l test' <host>:path .

sshpass with scp

sshpass -f ssh_pass scp <file> <user>@<host>:<path> 

sshpass no host key checking

Many times sshpass is used for automation in which you may not want host key checking to break your automated script. Host key checking may cause a silent failure in which you are not even sure what happened. To disable host key checking when using sshpass run this command.

sshpass -f pass_file ssh -oStrictHostKeyChecking=no <user>@<host>

sshpass use deprecated key algorithms

If you are connecting to an older linux os you may be required to pass a deprecated key algorithm. To do so run this command:

sshpass -f pass_file ssh -oHostKeyAlgorithms=+ssh-rsa <user>@<host>

Conclusion – sshpass ssh password authentication automation

Using sshpass for ssh password authentication automation can be an effective measure for automating password authenticated functions. Again, make sure to take the appropriate security measures to keep your password secure and not visible by unwelcome spectators.

Read more of our ssh related content.

linux,  ssh,  Ubuntu

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Popular Posts

PKCS12

openssl s_client

Keytool

Keytool list

ECDSA vs RSA

OpenSSL

PKCS7

Certificate Decoder

PKI for DevOps Engineers – Free Training Series

PKI for DevOps Training Hub

Lesson 1 – How TLS and PKI Work

Lesson 2 – Understanding X.509 Certificates

Lesson 3 – Certificate Chains Explained

Lesson 4 – Debug TLS with OpenSSL

Lesson 5 – Verify Certificate Chains

Lesson 6 – Creating CSRs with OpenSSL

Lesson 7 – Working with PKCS12 Certificates

Lesson 8 – Java Keystores and keytool

Lesson 9 – Certificate Expiration Monitoring

Lesson 10 – Automating Certificate Renewal

Lesson 11 – Common TLS Errors

Lesson 12 – PKI Architecture for DevOps

Recent Posts

  • Apache mod_auth_cas: Protect Web Applications with Apereo CAS and Docker
  • Apache mod_auth_mellon: Configure SAML SSO & Docker
  • Configure OpenID Connect (OIDC) in Apereo CAS 7.3 and 8
  • Certificate Ownership Is an Operating Model Problem, Not a Tooling Problem
  • OpenSSL dgst: Create Checksums and Verify Digital Signatures

Footer

  • Twitter
  • YouTube
Mister PKI

Practical security engineering for the systems that establish trust.

Learn OpenSSL Keytool Free training
Work together PKI consulting CAS consulting Sponsored contributions
Site About Support Mister PKI Cookie policy Search
© 2026 Mister PKI Secure systems. Clear guidance.