1

This works, but then I have to type the password manually

sftp -oStrictHostKeyChecking=no -i ./id_rsa user@host << !
  cd /path
!

This doesn't work. The command never completes execution

export SSHPASS=pass
sshpass -e sftp -oStrictHostKeyChecking=no -i ./id_rsa user@host << !
  cd /path
!

Have also tried this, but same outcome. The command never completes execution

sshpass -p pass sftp -oStrictHostKeyChecking=no -i ./id_rsa user@host << !
  cd /path
!
clarkk
  • 1,727
  • 6
  • 31
  • 43
  • Try this: remove `-b -`, like this: `echo 'cd /my-path' | sshpass -p my-pass sftp -oStrictHostKeyChecking=no -i ./id_rsa user@host` – Edgar Magallon Feb 07 '23 at 09:16
  • Is it asking for your user's password or the SSH key's password? – muru Feb 07 '23 at 09:33
  • @EdgarMagallon if I remove `-b -` the command never completes execution. `-` means that stdin is piped as the script file – clarkk Feb 07 '23 at 21:24
  • @clarkk In my case, removing `-b -` solves the problem. Because if I use the same command than yours (with `-b -`) I get the same error: *user@host: Permission denied (publickey,keyboard-interactive).* It seems that `sftp` by default read from `stdin`. Not sure what is wrong in your case, though – Edgar Magallon Feb 07 '23 at 21:31
  • Possible duplicate: [`ssh` works but `sshpass` doesn't - how is this possible?](https://unix.stackexchange.com/q/679175/108618). – Kamil Maciorowski Feb 09 '23 at 17:35
  • 1
    Side note: the title says "passphrase", the body says "password". OpenSSH in its documentation and messages uses the word "password" for a string that gives access to a server, "passphrase" for a string that gives access to a key. I observed there are people who use the word "password" for both; so do you, apparently; so does the author of [this answer](https://unix.stackexchange.com/a/734938/108618). IMO calling the passphrase "password" is technically wrong. Oh well… – Kamil Maciorowski Feb 09 '23 at 17:36

1 Answers1

0

It turns out my password also wasn't accepted using sshpass on Debian 11 running openssh-server with openssh-sftp-server. I had a look at the logs and could verify that the server is indeed waiting for the password to be entered.

The password prompt looks like this without sshpass:

$ sftp -oStrictHostKeyChecking=no -i ./id_rsa me@thething
Enter passphrase for key './id_rsa':

Looking at the man page of sshpass, I found this option:

-P    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:" and
      "password:"). If your client's prompt does not fall under either  of  these,
      you can override the default with this option.

Using -P and a matching keyword solved it.

$ echo "cd Downloads" | SSHPASS=testpass sshpass -P 'passphrase' -e sftp -oStrictHostKeyChecking=no -i ./id_rsa me@thething
Connected to thething.
sftp> cd Downloads
Freddy
  • 25,172
  • 1
  • 21
  • 60