GitHub Deploy Key Routing
Treat GitHub private repo access as a routing problem, not just a Git problem.
Core rules
- - Use one deploy key per private repository unless a machine user is intentionally chosen.
- Use one SSH host alias per key.
- Point each repo remote at the correct alias explicitly.
- Do not rely on a catch-all
Host github.com when multiple deploy keys exist. - Verify SSH first, then Git, then push.
- If automation is involved, fix both the live repo remote and the config/script source that writes it.
Canonical pattern
CODEBLOCK0
CODEBLOCK1
Use this skill when the machine has more than one private GitHub repo, more than one SSH key, or any recurring GitHub automation.
Quick triage
If you need the fastest route:
- 1. Read
references/symptoms.md and match the exact error. - Read
references/patterns.md and compare the current alias + remote layout. - Read
references/decision-guide.md only if the identity model itself is still undecided. - Read
references/openclaw-automation.md only when a script, backup flow, or config value may be rewriting the remote.
Workflow
1. Identify the repo + remote actually in use
Check the local repo path, current remotes, and whether the failing action came from:
- - an interactive repo command
- a backup/sync script
- a config file that stores the repo URL
- a cron/automation job
If the repo path and the config source differ, do not treat them as the same fix.
2. Identify the key-routing layer
Read references/patterns.md for the standard alias layout.
Read references/key-storage-by-system.md when OS-specific key locations or mixed Windows/WSL/macOS behavior may matter.
Ask:
- - Which SSH alias is the repo using now?
- Which key does that alias select?
- Is that key actually authorized for this repo?
- Is a broad
Host github.com rule hijacking traffic?
3. Diagnose by symptom
Read references/symptoms.md and match the exact failure string before changing anything.
4. Choose the right identity model
Read references/decision-guide.md when the user is deciding between:
- - deploy key
- personal SSH key
- machine user
Read references/identity-model-boundaries.md when the question is really about where SSH routing ends and GitHub API authority begins — especially for PR merge automation, release creation, or fine-grained PAT vs deploy key decisions.
5. Check automation-specific drift
Read references/openclaw-automation.md when the repo is used by OpenClaw backup/restore, plugins, cron jobs, or config-driven workflows.
6. Fix in the safe order
- 1. Fix or add the SSH alias.
- Verify with
ssh -G <alias>. - Test with
ssh -T git@<alias>. - Update the repo remote URL.
- Update any config/script source that still writes the old remote.
- Verify with
git ls-remote origin. - Only then push or pull.
Minimal command set
CODEBLOCK2
Bundled script
For a read-only audit of one local repo, run:
CODEBLOCK3
The script summarizes:
- - repo remotes
- inferred SSH alias from INLINECODE15
- INLINECODE16 files and permissions
- INLINECODE17 preview
- INLINECODE18 summary for the detected alias
Use the script to inspect before editing.
What to report
- - Root cause in one sentence
- Whether the failure is local config, GitHub permission, or both
- The minimal fix
- Exactly what changed
GitHub 部署密钥路由
将 GitHub 私有仓库访问视为路由问题,而不仅仅是 Git 问题。
核心规则
- - 每个私有仓库使用一个部署密钥,除非有意选择机器用户。
- 每个密钥使用一个 SSH 主机别名。
- 明确将每个仓库的远程地址指向正确的别名。
- 当存在多个部署密钥时,不要依赖通用的 Host github.com 配置。
- 先验证 SSH,再验证 Git,最后推送。
- 如果涉及自动化,同时修复实时仓库的远程地址和写入该地址的配置/脚本源。
标准模式
ssh
Host github.com-backup
HostName github.com
User git
IdentityFile ~/.ssh/openclawbackuped25519
IdentitiesOnly yes
bash
git remote set-url origin git@github.com-backup:OWNER/REPO.git
当机器上有多个私有 GitHub 仓库、多个 SSH 密钥或任何重复的 GitHub 自动化任务时,使用此技能。
快速排查
如果需要最快的排查路径:
- 1. 阅读 references/symptoms.md 并匹配确切的错误信息。
- 阅读 references/patterns.md 并对比当前的别名和远程地址布局。
- 仅在身份模型本身仍未确定时阅读 references/decision-guide.md。
- 仅在脚本、备份流程或配置值可能重写远程地址时阅读 references/openclaw-automation.md。
工作流程
1. 确定实际使用的仓库和远程地址
检查本地仓库路径、当前远程地址,以及失败操作来自:
- - 交互式仓库命令
- 备份/同步脚本
- 存储仓库 URL 的配置文件
- 定时任务/自动化作业
如果仓库路径和配置源不同,不要将它们视为同一修复对象。
2. 确定密钥路由层
阅读 references/patterns.md 了解标准别名布局。
当操作系统特定的密钥位置或混合 Windows/WSL/macOS 行为可能产生影响时,阅读 references/key-storage-by-system.md。
询问:
- - 仓库当前使用哪个 SSH 别名?
- 该别名选择了哪个密钥?
- 该密钥是否确实被授权用于此仓库?
- 是否有宽泛的 Host github.com 规则劫持了流量?
3. 根据症状诊断
在更改任何内容之前,阅读 references/symptoms.md 并匹配确切的失败字符串。
4. 选择正确的身份模型
当用户需要在以下选项之间做决定时,阅读 references/decision-guide.md:
当问题实际上是关于 SSH 路由的边界和 GitHub API 权限的起点时——特别是对于 PR 合并自动化、发布创建或细粒度 PAT 与部署密钥的决策——阅读 references/identity-model-boundaries.md。
5. 检查自动化相关的偏差
当仓库被 OpenClaw 备份/恢复、插件、定时任务或配置驱动的工作流使用时,阅读 references/openclaw-automation.md。
6. 按安全顺序修复
- 1. 修复或添加 SSH 别名。
- 使用 ssh -G <别名> 验证。
- 使用 ssh -T git@<别名> 测试。
- 更新仓库远程 URL。
- 更新仍写入旧远程地址的配置/脚本源。
- 使用 git ls-remote origin 验证。
- 然后才能推送或拉取。
最小命令集
bash
ls -la ~/.ssh
sed -n 1,200p ~/.ssh/config
git remote -v
ssh -G <主机别名> | sed -n 1,40p
ssh -T git@<主机别名>
git ls-remote origin
捆绑脚本
要对一个本地仓库进行只读审计,运行:
bash
scripts/audit-routing.sh /path/to/repo
该脚本会汇总:
- - 仓库远程地址
- 从 origin 推断的 SSH 别名
- ~/.ssh 文件和权限
- ~/.ssh/config 预览
- 检测到的别名的 ssh -G 摘要
在编辑前使用该脚本进行检查。
需要报告的内容
- - 一句话说明根本原因
- 失败是本地配置问题、GitHub 权限问题,还是两者兼有
- 最小的修复方案
- 具体更改了什么