我在~/.ssh/config
设置了这样的内容:
#Account one
Host one.gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
#Account two
Host two.gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_mastersystem
然后我尝试像这样测试:
它的成功
注意:
名称1 =摩西toh,用户名2 = moschel(我在2年前创建此帐号)
名称2 =摩西,用户名2 = moses639(我昨天创建了此帐户)
然后我尝试推送到gitlab
存在这样的错误:
remote: Access denied
fatal: unable to access 'https://gitlab.com/xxxxx/myproject.git/': The requested URL returned error: 403
然后我再次尝试使用其他帐户推送到gitlab
存在这样的错误:
remote: Access denied
fatal: unable to access 'https://gitlab.com/xxxxx/myproject.git/': The requested URL returned error: 403
答案 0 :(得分:2)
好吧,首先你的测试是错误的。关键是不要给身份文件提供命令,而是通过主机名,所以试试ssh git@one.gitlab.com
和ssh git@two.gitlab.com
,你应该得到不同的名字。您的SSH配置很快就会看起来很好。
另一点是,你说“尝试推送”和“尝试推送另一个帐户”,但你不这样做。如果您认为git remote add moses639 https://gitlab.com/xxxxx/myproject
将以用户moses639
推送,这是完全错误的,因为这只是您配置的遥控器的本地名称,您可以将其命名为foo
,它仍然没有区别
此外,您使用https
个网址。如果要通过SSH配置文件选择标识,则无效。您必须通过SSH协议克隆(或实际推送),然后不使用gitlab.com
作为主机名,而是使用one.gitlab.com
或two.gitlab.com
,具体取决于您要使用的身份。实际上,您可以使用gitlab.com
和two.gitlab.com
,因为one.gitlab.com
无论如何都会使用默认密钥进行识别。