sshpass

TLDR

SSH with password
$ sshpass -p '[password]' ssh [user@host]
SSH with password from file
$ sshpass -f [password_file] ssh [user@host]
SSH with password from env var
$ SSHPASS='[password]' sshpass -e ssh [user@host]
SCP with password
$ sshpass -p '[password]' scp [file] [user@host:/path/]
Rsync with password
$ sshpass -p '[password]' rsync -avz [files] [user@host:/path/]

SYNOPSIS

sshpass [-p password] [-f file] [-e] [options] command [args]

DESCRIPTION

sshpass provides password authentication for SSH without interactive input. It enables automation where key-based auth isn't available.Password sources include command line, files, and environment variables. File-based passwords are safer than command-line exposure.The tool works with any program expecting SSH-style password prompts: ssh, scp, rsync, and others.First-time connections need host key handling. Use -o StrictHostKeyChecking=no for automation, though this has security implications.For most uses, SSH keys are preferred. sshpass fills gaps where key auth isn't possible or practical.

PARAMETERS

-p PASSWORD

Password on command line.
-f FILE
Read password from file.
-e
Read from SSHPASS env variable.
-d FD
Read from file descriptor.
-P PROMPT
Set password prompt pattern.
-v
Verbose mode.
-h
Show help.
-V
Show version.

INSTALL

sudo apt install sshpass
sudo dnf install sshpass
sudo pacman -S sshpass
sudo apk add sshpass
sudo zypper install sshpass
brew install sshpass
nix profile install nixpkgs#sshpass

CAVEATS

Command-line passwords visible in process list. Less secure than SSH keys. Not recommended for interactive use. May expose passwords in logs.

HISTORY

sshpass was written by Shachar Shemesh to address the need for non-interactive SSH password entry in scripts and automation where key-based authentication wasn't feasible.

SEE ALSO

ssh(1), ssh-keygen(1), expect(1), ssh-agent(1)

RESOURCES

Homepage