【问题标题】:ssh with -oBatchMode=yes fails; without succeeds - no password requested带有 -oBatchMode=yes 的 ssh 失败;没有成功 - 没有要求密码
【发布时间】:2017-10-12 12:50:50
【问题描述】:

我正在使用 -oBatchMode=yes 来禁止交互式密码,以防密钥配置错误。

我使用“diff”来比较调试输出,直到“服务器接受密钥:pkalg ssh-rsa blen 279”之前没有任何变化,其中下一行是“身份验证成功”或尝试更多私钥。

从脚本和命令行,不使用批处理模式运行会导致成功登录:

$ ssh -v  qa@192.168.19.81  uptime
.
.
Warning: Permanently added '192.168.19.81' (ECDSA) to the list of known hosts.
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/tim/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
--- things change from here
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.19.81 ([192.168.19.81]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Requesting authentication agent forwarding.
debug1: Sending command: uptime
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
13:24  up 3 days,  3:04, 2 users, load averages: 1.76 1.62 1.61
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2768, received 3080 bytes, in 0.0 seconds
Bytes per second: sent 129171.8, received 143731.6
debug1: Exit status 0

但是 -oBatchMode=yes 也会失败:

$ ssh -v -oBatchMode=yes  qa@192.168.19.81  uptime
OpenSSH_7.4p1, LibreSSL 2.5.0
.
.
debug1: Offering RSA public key: /Users/tim/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
--- things change from here
debug1: Trying private key: /Users/tim/.ssh/id_dsa
debug1: Trying private key: /Users/tim/.ssh/id_ecdsa
debug1: Trying private key: /Users/tim/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey,password,keyboard-interactive).
$

远程机器: 达尔文 qa-ffc-mbp-2.lnd 16.7.0 达尔文内核版本 16.7.0:2017 年 6 月 15 日星期四 17:36:27 PDT;根:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

我的机器: Darwin TimBs-MacBook-Pro-3483.local 16.6.0 达尔文内核版本 16.6.0:2017 年 4 月 14 日星期五 16:21:16 PDT;根:xnu-3789.60.24~6/RELEASE_X86_64 x86_64


更新:我从没有此问题的帐户复制了 id_rsa 和 id_rsa.pub,它开始工作。但是我的 id_rsa.pub 正确地列在了目标机器的 authorized_keys 中。我什至从私钥中重新生成了我的公钥,以防它被损坏。没有骰子。出于显而易见的原因,我不愿意更改密钥。

【问题讨论】:

    标签: macos ssh


    【解决方案1】:

    您可以尝试将这些行添加到您的 ~/.ssh/config 文件中:

    Host *
    UseKeychain yes
    AddKeysToAgent yes
    

    【讨论】:

    • 感谢您 - 我通过其他方式解决了这个问题。如果问题再次发生,我会尝试的!
    【解决方案2】:

    似乎Apple的钥匙串集成被BatchMode=yes禁用

    如果我 eval $(ssh-agent)ssh-add 我的身份,一切正常。

    另一个帐户的密钥有效的原因是它的密码是空的。

    【讨论】:

      猜你喜欢
      • 2020-09-04
      • 1970-01-01
      • 2020-09-03
      • 2015-08-27
      • 2017-02-11
      • 1970-01-01
      • 1970-01-01
      • 2019-05-11
      • 2015-01-15
      相关资源
      最近更新 更多