LinuxCommandLibrary

sshpass

Provide SSH password non-interactively

TLDR

Connect to a remote server using a password supplied on a file descriptor (in this case, stdin)

$ sshpass -d [0] ssh [user]@[hostname]
copy

Connect to a remote server with the password supplied as an option, and automatically accept unknown SSH keys
$ sshpass -p [password] ssh -o StrictHostKeyChecking=no [user]@[hostname]
copy

Connect to a remote server using the first line of a file as the password, automatically accept unknown SSH keys, and launch a command
$ sshpass -f [path/to/file] ssh -o StrictHostKeyChecking=no [user]@[hostname] "[command]"
copy

SYNOPSIS

sshpass [-hVp] [-d num] [-e] [-f file] [-i interface] [-P prompt] command

PARAMETERS

-h
    Display the help message and exit.

-V
    Display the version number and exit.

-p password
    Specify the password directly on the command line.

-d num
    Specify a delimiter character for splitting the password.

-e
    Get the password from the SSHPASS environment variable.

-f file
    Get the password from the first line of the specified file.

-i interface
    Specify the network interface to use for connecting to the SSH server.

-P prompt
    Sets the ssh prompt. It can be set to any string (or regexp).

DESCRIPTION

sshpass is a non-interactive password provider for ssh.
It's designed to provide passwords to ssh in situations where interactive password prompts are not possible, such as in scripts or automated systems.

Using sshpass is generally discouraged due to security concerns, as it involves storing or passing passwords in plain text. It's highly recommended to use key-based authentication with ssh keys instead of passwords whenever possible.
However, in very specific and controlled environments where key-based authentication isn't feasible, sshpass might be considered with extreme caution.
Note that many systems prohibit the use of sshpass. Consult the local information security policy.

CAVEATS

sshpass is inherently insecure due to its handling of passwords in plain text. Avoid using it if possible, and consider alternative authentication methods such as ssh keys. Using sshpass can violate security policies and expose sensitive information. It should not be used in production environments or on systems handling sensitive data, unless absolutely necessary and with appropriate security controls in place. Many implementations of SSH clients do not allow to use sshpass.

SECURITY CONSIDERATIONS

The primary risk associated with sshpass is the storage and transmission of passwords in plain text. This makes it vulnerable to interception and unauthorized access. If the password is included on the command line, it may be visible in process listings. If the password is stored in a file, the file must be carefully protected with restrictive permissions. The best practice is to use ssh keys.

SEE ALSO

ssh(1), ssh-keygen(1)

Copied to clipboard