Git客户端忽略SSH配置

时间:2015-06-05 22:07:45

标签: git ssh gitlab

我与两个不同的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文件中有什么问题? 非常感谢你提前。

1 个答案:

答案 0 :(得分:4)

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

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

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

有关详情,请查看man ssh_config

相关问题