[英]Git config error on setup multiple ssh on github
我正在尝试设置我的 git 配置以选择对应于每种情况的 ssh
Host github.com_enterprise
Hostname github.com
User user_enterprise@enterprise.com
IdentityFile ~/.ssh/id_enterprise_ssh
Host github.com_personal
Hostname github.com
User user_personal@personal.com
IdentityFile ~/.ssh/id_personal_ssh
或者
Host github.com:enterprise
Hostname github.com
User user_enterprise@enterprise.com
IdentityFile ~/.ssh/id_enterprise_ssh
Host github.com:personal
Hostname github.com
User user_personal@personal.com
IdentityFile ~/.ssh/id_personal_ssh
我发现主机应该是别名,但它不起作用。 例如,如果想让 git 克隆与 id_enterprise_ssh 一起工作,我要做的是
Host github.com
Hostname github.com
User user_enterprise@enterprise.com
IdentityFile ~/.ssh/id_enterprise_ssh
我必须通过删除_enterprise
并删除其他github.com_personal
信息来编辑主机。 所以,我想知道我的配置设置中缺少什么
When you use ssh via something like git clone git@github.com:your-username/your-repo.git
, SSH is looking for github.com
to match the Host <X>
alias, not the Hostname value. 因此,如果您使用 ssh_config 的第一个选项,您的 SSH 相关命令应如下所示:
git clone git@github.com_personal:<org>/<repo>.git
请注意,一旦开始执行此操作,您可能必须确保您的远程 URL 配置正确(也就是说,他们说github.com_personal
和github.com_enterprise
)。 您可以使用git remote -v
检查。 您还必须确保将所有相关的 SSH 密钥添加到您的 SSH 代理中。
Considering an SSH URL for github.com
will always use git@
as a remote user, do replace in each of your Host entry a line:
User git
这样,您可以测试您的每个主机条目
ssh -Tv github.com_personal
ssh -Tv github.com_enterprise
在这两种情况下,您都应该看到一条欢迎消息,其中包含正确的个人或企业用户名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.