← 返回命令列表

Linux command

sshpass 命令

网络

需要网络或远程资源。

常用示例

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/]

说明

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.

参数

-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.

FAQ

What is the sshpass command used for?

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.

How do I run a basic sshpass example?

Run `sshpass -p '[password]' ssh [user@host]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -p _PASSWORD_ do in sshpass?

Password on command line.