【问题标题】:Using SSH to push to 2 different repos using the same account?使用 SSH 使用同一帐户推送到 2 个不同的存储库?
【发布时间】:2016-11-26 02:39:38
【问题描述】:

我在 Github 上的同一帐户上的一台机器上有两个存储库。我已将 ssh 密钥添加到我的帐户并成功推送到存储库 A,但我无法推送到存储库 B。github 上的 SSH 密钥未与特定存储库 iirc 关联。

一点研究让我发现我需要两个不同的密钥。如何编辑我的配置文件,以便 git 在推送到第二个 repo 时使用正确的密钥?

【问题讨论】:

  • 您不需要 2 把钥匙。你遇到了什么错误?
  • 权限被拒绝(公钥)。但是推动回购 A 工作正常
  • 确保两个 repos 在同一个帐户下。您可以为您的两个存储库附加git ls-remote --get-url origin 的输出吗?

标签: linux git github ssh


【解决方案1】:

我通过修改 .ssh/config 文件来追加这个解决方案

Host repo2.github.com
  User git
  Port 22
  Hostname github.com
  IdentityFile ~/.ssh/id_rsa2
  TCPKeepAlive yes
  IdentitiesOnly yes
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no

然后通过在 .git/config 文件中附加以下内容来添加

[remote "origin"]
    url = git@repo2.github.com:[Username]/G2-FrontEnd.git
    fetch = +refs/heads/*:refs/remotes/origin/*

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-07
    • 1970-01-01
    • 2019-09-18
    • 2013-05-16
    • 1970-01-01
    相关资源
    最近更新 更多