首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有密码的SFTP (一行命令)

带有密码的SFTP (一行命令)
EN

Unix & Linux用户
提问于 2023-02-06 16:47:04
回答 1查看 1.3K关注 0票数 1

这是可行的,但是我必须手动输入密码。

代码语言:javascript
复制
sftp -oStrictHostKeyChecking=no -i ./id_rsa user@host << !
  cd /path
!

这不管用。命令永远不会完成执行。

代码语言:javascript
复制
export SSHPASS=pass
sshpass -e sftp -oStrictHostKeyChecking=no -i ./id_rsa user@host << !
  cd /path
!

也尝试过,但结果是一样的。命令永远不会完成执行。

代码语言:javascript
复制
sshpass -p pass sftp -oStrictHostKeyChecking=no -i ./id_rsa user@host << !
  cd /path
!
EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2023-02-09 17:08:41

事实证明,我的密码也没有被接受使用sshpass在Debian 11上运行openssh服务器openssh-sftp服务器。我查看了日志,可以验证服务器确实在等待输入密码。

在没有sshpass的情况下,密码提示如下所示:

代码语言:javascript
复制
$ sftp -oStrictHostKeyChecking=no -i ./id_rsa me@thething
Enter passphrase for key './id_rsa':

查看sshpass的手册页,我发现了以下选项:

代码语言:javascript
复制
-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和匹配关键字解决了它。

代码语言:javascript
复制
$ echo "cd Downloads" | SSHPASS=testpass sshpass -P 'passphrase' -e sftp -oStrictHostKeyChecking=no -i ./id_rsa me@thething
Connected to thething.
sftp> cd Downloads
票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/734565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档