ssh到两个独立的gitlab帐户
我有两个独立的ssh到两个独立的gitlab帐户,git,github,ssh,gitlab,Git,Github,Ssh,Gitlab,我有两个独立的gitlab帐户,每个帐户都有一个唯一的SSH密钥,并使用不同的电子邮件创建。如何从两个帐户的回购中正常地(git push origin master/git pull origin master)推/拉?我必须同时配置~/.gitconfig和~/.ssh/config吗 第一个gitlab帐户(用户名1,email1@gmail.com) 第二个gitlab帐户(用户名2,email2@gmail.com) ~/.ssh/config Host gitlab.com
gitlab
帐户,每个帐户都有一个唯一的SSH
密钥,并使用不同的电子邮件创建。如何从两个帐户的回购中正常地(git push origin master/git pull origin master
)推/拉
?我必须同时配置~/.gitconfig和~/.ssh/config吗
第一个gitlab帐户(用户名1,email1@gmail.com)
第二个gitlab帐户(用户名2,email2@gmail.com)
~/.ssh/config
Host gitlab.com
User username1
IdentityFile ~/.ssh/id_rsa
Host gitlab.com
User username2
IdentityFile ~/.ssh/id_rsa_
~/.gitconfig
[user]
name = Bob
email = email1@gmail.com
username = username1
问题是,我只能使用这种配置从一个回购中提取,而不能同时从两个回购中提取。如何使它同时适用于两者?您可以通过编辑yout~/.ssh/config来做到这一点
Host gitlab.com
User username1
IdentityFile ~/.ssh/id_rsa
Host gitlab.com
User username2
IdentityFile ~/.ssh/id_rsa_
这里你为每个帐户添加两个部分。就像这个例子
#user1 account
Host gitlab.com-user1
HostName gitlab.com
User git
IdentityFile ~/.ssh/gitlab-user1
#user2 account
Host gitlab.com-user2
HostName gitlab.com
User git
IdentityFile ~/.ssh/gitlab-user2
然后您必须更改远程url,如下所示
使用帐户1
git@gitlab.com-用户1:
使用帐户2
git@gitlab.com-用户2:
希望这有帮助 这很好,但这是否意味着我必须在我的gitlab帐户中始终更改每次回购的远程url?@user3226932您必须在本地克隆中更改远程url,而不是在gitlab direct中。如果只更改一个帐户的url,并将一个帐户的ssh配置更改为Host gitlab.com,则可以尝试