macos - 带有 -oBatchMode=yes 的 ssh 失败;没有成功 - 没有要求密码

标签 macos ssh

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

我使用“diff”来比较调试输出,直到“服务器接受 key :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).
$

远程机器:
Darwin qa-ffc-mbp-2.lnd 16.7.0 Darwin 内核版本 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 Darwin 内核版本 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 中。我什至从私钥重新生成了我的公钥,以防它被损坏。没有骰子。出于显而易见的原因,我不愿意更改我的 key 。

最佳答案

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

Host *
UseKeychain yes
AddKeysToAgent yes

关于macos - 带有 -oBatchMode=yes 的 ssh 失败;没有成功 - 没有要求密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46710087/

相关文章:

xcode - Github 操作 : xcodebuild fails due to server fingerprint

git - 如何为每个 git 存储库管理一个唯一的 key ?

java - 在 Mac OS X 上最小化后 JFrame 不刷新

windows - 我应该为 Windows 7 分区留出多少空间?

python - 使用 Python 压缩 Mac 应用程序包

mysql - 将远程表导入远程mysql服务器

git - 让 Jenkins 通过 SSH 连接到服务器并从 git 中提取 - 构建后

ssh - 安装pagespeed

macos - 使用带有 Interfacebuilder 的 NSPageController 来设置 View

swift - NSVisualEffectView 淡入淡出动画