【问题标题】:Setting up multiple SSH key access to Github设置对 Github 的多个 SSH 密钥访问
【发布时间】:2023-03-07 01:16:01
【问题描述】:

我正在尝试配置远程 linux 机器来访问我拥有的两个不同的 git 帐户。我不断获得身份验证访问权限。

> git push
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我已经采取的步骤,

  1. 生成了两组 ssh 密钥(称它们为 key1 和 key2)
  2. 在~/.ssh/config 生成了一个配置文件
  3. 编辑了那个文件
    1 # Default github account: key1
      2 Host github.com
      3    HostName github.com
      4    IdentityFile ~/.ssh/key1
      5    IdentitiesOnly yes
      6
      7 # Other github account: key2
      8 Host github-key2
      9    HostName github.com
     10    IdentityFile ~/.ssh/key2
     11    IdentitiesOnly yes
  1. 在用户帐户settings/ssh keys下的两个git帐户中添加了.pub版本。
  2. 用ssh-add ~/.ssh/key1将它们添加到我的虚拟机上

我真的不确定从这里去哪里以及下一步是什么,为什么这不起作用。我觉得我可能缺少一个步骤。

【问题讨论】:

    标签: git github ssh


    【解决方案1】:

    tl;dr:将以下条目添加到您的 ~/.ssh/config,其中 $user 是 GitHub 用户名,$key 是为该用户指定并在该 GitHub 用户的设置中定义的私钥:

    Host github.com-$user
        Hostname github.com
        User git
        IdentityFile ~/.ssh/$key
        IdentitiesOnly yes
    

    然后,配置你的 git 远程 URL:

    git remote add origin git@github.com-$user:$user/$repo
    

    基本上,我有一个用于工作/个人项目的长期运行的 SSH 密钥,然后想为不相关的副项目添加一个新密钥。我完成了您在问题中概述的所有步骤,但仍然遇到相同的错误。执行$ GIT_SSH_COMMAND='ssh -v' git fetch 表明 git 首先传递了我的主用户的私钥,即使它正确地作为有效密钥进行身份验证,该用户当然对新用户的私有存储库没有权限。

    这篇文章是相关的:https://medium.com/@ordinary.yobi/multiple-ssh-keys-on-github-f75a372d5374

    这是我的第一个答案,希望对您有所帮助。我刚才确实刚刚解决了这个确切的问题,这非常令人沮丧。

    编辑: 哎呀,忘记了关键部分。对不起!

    【讨论】:

      猜你喜欢
      • 2012-06-07
      • 1970-01-01
      • 2014-02-19
      • 2017-09-15
      • 2013-05-16
      • 2021-09-07
      • 2014-10-28
      • 1970-01-01
      相关资源
      最近更新 更多