我想在Gitlab网站上使用2个帐户,每个帐户使用不同的ssh密钥
我成功生成了密钥并将它们添加到~/.ssh 我创建~/.ssh/config文件的文件夹中并使用其中一个,它的工作正常我也可以通过编辑~/.ssh/config文件在两个密钥之间进行交换
问题是:我想在同一时间使用它们,但我找到的所有教程都采用了不同的主机:/
实际上我的两个帐户都在同一个主机上
如何编辑~/.ssh/config文件以接受同一主机的两个帐户
注意: 我读过这个问题,但我无法从中获得帮助
我的两个帐户是username1和username2
repo URL看起来像:git@gitlab.com:username1/test-project.git
我目前的~/.ssh/config档案:
Host gitlab.com-username1
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa
Host gitlab.com-username2
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa_username2
Run Code Online (Sandbox Code Playgroud)
更新1:
1)当我在~/.ssh/config文件中使用一个键时,一切都很完美(但每次我想要更改我使用的用户时更新它都很无聊)
2)当我使用这条线时,
ssh -T git@gitlab.com-username1
ssh -T git@gitlab.com-username2
它的效果很好,并返回一条欢迎信息
从1)和2),我认为问题肯定来自~/.ssh/config文件,特别是Host变量
更新2:(求解)
求解是编辑.git/config从文件
[remote "origin"]
url = git@gitlab.com:username1/test-project.git
到
[remote "origin"]
url = git@gitlab.com-username1:username1/test-project.git
并为此做同样的事情 username2