gpt4 book ai didi

git - SSH 配置被 git 客户端忽略

转载 作者:太空狗 更新时间:2023-10-29 13:59:53 28 4
gpt4 key购买 nike

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

因为我需要使用不同的用户(和电子邮件)来访问它们,所以我创建了两个 ssh key :假设是 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 搜索 key 时将其考虑在内?

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

我的 config 文件到底出了什么问题?非常感谢您。

最佳答案

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

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

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

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

关于git - SSH 配置被 git 客户端忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30676524/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com