ssh prompts for and reads password (or passphrase) using the terminal (
/dev/tty), not its stdin. This way you can pipe/redirect data to/from
ssh and still be able to provide a password when asked. But to provide a password not via the terminal, one needs to present a "fake" terminal to
ssh. This is what
sshpass … ssh …,
ssh in a dedicated emulated terminal. This means
ssh does not read directly from your terminal,
sshpass does. And
ssh does not print directly to your terminal,
sshpass does. Eventually
sshpass will act as a relay, so it will be as if
ssh used your terminal. But before this happens,
sshpass intercepts what
ssh prints; it also injects the string you specify after
ssh "sees" the string as coming from the terminal
ssh is using (which is not your terminal). This way
ssh can be fooled you typed the password, when it's
sshpass who "typed".
sshpass waits for
assword1?) to appear as a part of the prompt for password. E.g. if you didn't use a key and you didn't use
ssh would print:
[email protected]'s password:
and it would wait for you to type your password. If you used
sshpass to provide your password, then
sshpass would intercept this message and "type" the password for you. By waiting for the right prompt
sshpass knows when
ssh expects a password, only then it passes your password.
In your case the prompt was different.
ssh did not ask for the password, it asked for the passphrase using a different prompt. The prompt from
ssh was exactly
Enter passphrase for key '/home/user1/.ssh/id_rsa':, there was nothing matching
sshpass kept waiting for the default prompt that never came.
-P to override the default.
Set the password prompt. Sshpass searched for this prompt in the program's output to the TTY as an indication when to send the password. By default sshpass looks for the string
assword: (which matches both
password:). If your client's prompt does not fall under either of these, you can override the default with this option.
man 1 sshpass)
In your case it may be:
sshpass -P assphrase -p "pass" ssh [email protected]
Enter passphrase … coming from the
ssh, it will respond with whatever you specified after
-p. Next it will sit as a relay between your terminal and the one
ssh is using; it will become transparent.
sshpass can be used to provide a password (a string in general) to any tool that normally uses the terminal (as opposed to stdin+stdout+stderr) to prompt for and read the password.
-P allows you to adjust the command to the prompt the tool uses.
1 The manual says
assword:, but the output from your
sshpass -v says
using match "assword". One way or another you need
-P to properly pass a passphrase.