【问题标题】:Error out instead of asking for passphrase with SSH错误而不是通过 SSH 询问密码
【发布时间】:2014-04-11 22:57:41
【问题描述】:

我正在编写一个使用 rsync 的脚本,如果 SSH 密钥有密码,我希望它出错,告诉用户改用非密码保护的密钥(因为脚本在后台运行)。

但是,我为 SSH 尝试过的所有标志都没有这样做,而且我在手册页中也找不到任何东西。

禁用 SSH 密码提示的最佳方法是什么?

【问题讨论】:

  • 是的,禁用密码验证,而不是用于公钥验证的密码短语
  • 显然,抱歉没有仔细阅读。由于用户将执行脚本,我是否正确假设脚本将能够访问用户的私钥(或者您认为在脚本中可以这样做)?

标签: php linux bash ssh


【解决方案1】:

您可以使用BatchMode 选项执行此操作。这将使 SSH 避免任何可能导致脚本挂起的事情,例如密码/密码提示。

这个例子直接取自http://www.unix.com/programming/184775-test-ssh-but-do-not-return-password-prompt.html提出的类似问题

if ssh -o BatchMode=yes "$hostname" true 2>/dev/null; then
    echo "it works"
else
    echo "it's broken."
if

这是一个使用 rsync 的示例:

rsync -e "ssh -o BatchMode=yes -i /var/www/.ssh/id_rsa" /path/to/test/file.txt remotehost:/path/to/test/file.txt

【讨论】:

  • 我已经在使用带有-e 标志的rsync 来指定SSH 命令,所以我可以添加BatchMode 标志。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-19
相关资源
最近更新 更多