这可行,但我必须手动输入密码
sftp -oStrictHostKeyChecking=no -i ./id_rsa user@host << !
cd /path
!
这是行不通的。该命令永远不会完成执行
export SSHPASS=pass
sshpass -e sftp -oStrictHostKeyChecking=no -i ./id_rsa user@host << !
cd /path
!
也尝试过这个,但结果相同。该命令永远不会完成执行
sshpass -p pass sftp -oStrictHostKeyChecking=no -i ./id_rsa user@host << !
cd /path
!
答案1
事实证明,sshpass
在运行 Debian 11 时我的密码也不被接受openssh 服务器
和openssh-sftp-服务器。我查看了日志,可以验证服务器确实正在等待输入密码。
如果不输入任何字符,密码提示如下sshpass
:
$ sftp -oStrictHostKeyChecking=no -i ./id_rsa me@thething
Enter passphrase for key './id_rsa':
查看 sshpass 的手册页,我发现了这个选项:
-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.
使用-P
和匹配的关键字解决了这个问题。
$ echo "cd Downloads" | SSHPASS=testpass sshpass -P 'passphrase' -e sftp -oStrictHostKeyChecking=no -i ./id_rsa me@thething
Connected to thething.
sftp> cd Downloads