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
  • Try this: remove -b -, like this: echo 'cd /my-path' | sshpass -p my-pass sftp -oStrictHostKeyChecking=no -i ./id_rsa user@host Commented Feb 7, 2023 at 9:16
  • Is it asking for your user's password or the SSH key's password?
    – muru
    Commented Feb 7, 2023 at 9:33
  • @EdgarMagallon if I remove -b - the command never completes execution. - means that stdin is piped as the script file
    – clarkk
    Commented Feb 7, 2023 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 Commented Feb 7, 2023 at 21:31
  • 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. IMO calling the passphrase "password" is technically wrong. Oh well… Commented Feb 9, 2023 at 17:36

1 Answer 1


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .