Lobsters | 📄 原文链接 | 2026-07-22 collected

GitHub 突然拒绝了我的 SSH 密钥(修复方法居然是一个 .pub 文件?!)

source: thorsell.io — 2026-07-21

概述

作者某天 git pull 突然报 Permission denied,密钥完好、配置正确、GitHub 状态正常,却死活连不上。排查后发现,缺少配套的 .pub 文件导致 OpenSSH 跳过公钥探测,直接发送签名认证请求——而 GitHub 新的 SSH 前端(6a2c000)拒绝这种直接签名的请求。运行 ssh-keygen -y -f ~/.ssh/github_rsa > ~/.ssh/github_rsa.pub 即可修复。两种流程都符合 RFC 4252,但 GitHub 的服务端更新打破了这个兼容性。

核心要点

  • .pub 文件缺失会改变 OpenSSH 的认证流程:有 .pub 时先探测公钥再签名,无 .pub 时直接发签名请求。
  • GitHub 的新 SSH 前端标识为 6a2c000,替代了之前的 babeld,该前端拒绝直接签名的 publickey 请求。
  • 通过 ssh-keygen -y -f 从私钥重新生成 .pub 文件即可解决问题,十二次对照测试 100% 可复现。
  • 两种认证流程均符合 RFC 4252 规范,说明这是实现层面的兼容性选择而非协议违规。

金句

With a .pub file present, the client first probes and only then signs. With only a private key, OpenSSH skips the probe and sends a fully signed authentication request directly.
back to Lobsters