【问题标题】:SSH Config is ignored by git clientSSH 配置被 git 客户端忽略
【发布时间】:2015-08-20 23:51:20
【问题描述】:

我与两个不同的 git 存储库交互,它们都是 GitLab 实现。

因为我需要使用不同的用户(和电子邮件)来访问它们,所以我创建了两个 ssh 密钥:假设是 id_rsa_1id_rsa_2。之后我写了一个~/.ssh/config 文件来指定每个id_rsa 文件应该在什么时候被使用。配置文件是:

Host gitlab.host1.com-user1
    HostName gitlab.host1.com
    User user1
    IdentityFile ~/.ssh/id_rsa_1

Host gitlab.host2.com-user2
    HostName gitlab.host2.com
    User user2
    IdentityFile ~/.ssh/id_rsa_2

我的问题是每次使用git 时,都没有考虑到config 文件。它一直在寻找 id_rsa 文件。

我的配置文件有什么问题? Host 只是个人标识符还是在 git 搜索密钥时考虑在内?

我应该提供哪个用户? “git”还是我在每台服务器上注册的真实用户?

我的config 文件中有什么问题? 非常感谢您。

【问题讨论】:

    标签: git ssh gitlab


    【解决方案1】:

    Host 条目是与您在查找密钥时请求的主机匹配的模式。然后,HostName 是实际登录的主机,默认为 Host 的值。所以,你可以说:

    Host gitlab.host1.com
        User user1
        IdentityFile ~/.ssh/id_rsa_1
    

    您也可以在调用 git 时指定 gitlab.host1.com-user1 作为主机,它应该适用于您当前的配置。

    更多信息,您可以查看man ssh_config

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 2021-07-02
      相关资源
      最近更新 更多