【问题标题】:Git push: how to avoid username and password in multiple repository?Git push:如何避免多个存储库中的用户名和密码?
【发布时间】:2016-12-23 16:20:42
【问题描述】:

我参考Git push: username, password, how to avoid? 设置我的 ssh 密钥,它可以工作。

但是现在,我将 另一个存储库 克隆到我的计算机中,我再次参考该指南,将我的 ~/.ssh/id_rsa.pub 的内容复制到此存储库的部署密钥中, github 告诉我“密钥已在使用中”。

如何避免两个存储库中的用户名和密码?

【问题讨论】:

  • 我认为你不需要一次又一次地这样做。
  • 我的第一个存储库不需要密码,但我的第二个需要。我能做些什么不需要密码?
  • 您应该通过ssh 而不是https 克隆存储库。

标签: git github ssh


【解决方案1】:

如果您正在克隆存储库以供自己使用(而不是部署到服务器等),您应该通过 https://github.com/settings/keys 将您的 SSH 密钥添加到您的 GitHub 配置文件中。这样就不需要为每个存储库添加单独的密钥了。

然后,使用 SSH URL(不是 HTTPS)克隆存储库。例如,如果您的存储库位于 https://github.com/youruser/yourrepo,请执行 git clone git@github.com:youruser/yourrepo.git

【讨论】:

    【解决方案2】:

    将本地计算机的 ssh 密钥 (id_rsa.pub) 添加到 Github 后。那么您应该始终使用ssh 而不是https 来克隆存储库。

    git clone https://github.com/user_name/repo
    git clone git clone git@github.com:user_name/repo.git
    

    如果您添加了ssh 键,请务必先避免。

    【讨论】:

      猜你喜欢
      • 2014-04-02
      • 2015-06-28
      • 1970-01-01
      • 2012-08-28
      • 1970-01-01
      • 1970-01-01
      • 2015-04-24
      相关资源
      最近更新 更多