You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub提示“key already in use”问题咨询及SSH密钥相关疑问

GitHub SSH公钥问题解答

问题1:GitHub是否仅允许存储一个SSH公钥?同一公钥能否在多个GitHub账户中存储?

  • GitHub允许单个账户添加多个SSH公钥,没有硬性数量限制,只要密钥格式符合要求(如ed25519、RSA等类型)即可。
  • 同一SSH公钥绝对不能在多个GitHub账户中存储。GitHub会在全局范围内检测公钥的唯一性,一旦某个公钥被绑定到任意一个账户,其他账户就无法再添加该公钥——这就是你收到"Key is already in use"提示的直接原因,你的公钥已被同事添加到他的账户中。

问题2:使用多个SSH公钥能否解决当前问题?这是否为通用且正确的处理方式?

  • 生成并使用多个SSH公钥完全可以解决当前问题,这是处理多GitHub账户/多场景密钥需求的通用且标准方案。
  • 具体操作步骤:
    1. 生成新的SSH密钥对(针对你的个人GitHub账户):
      ssh-keygen -t ed25519 -C "your-personal-email@example.com"
      
      执行命令时,按提示指定不同的存储路径(如~/.ssh/id_ed25519_personal),避免覆盖原有密钥。
    2. 登录个人GitHub账户,将新生成的公钥(id_ed25519_personal.pub内的内容)添加到账户的SSH密钥列表中。
    3. 配置~/.ssh/config文件,让Git自动为不同仓库匹配对应密钥:
      # 个人GitHub账户配置
      Host github-personal
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_ed25519_personal
      
      # 同事项目配置(使用原有密钥)
      Host github-colleague
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_ed25519
      
    4. 后续操作仓库时,用配置的Host别名代替默认的github.com:
      • 克隆个人仓库:git clone git@github-personal:your-username/your-repo.git
      • 拉取同事仓库:git clone git@github-colleague:colleague-username/their-repo.git

内容的提问来源于stack exchange,提问作者Max Pattern

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 19:15:31