如何使用两个不同的ssh用户连接到GitLab?
我有两个GitLab帐户——一个用于我的个人项目,一个用于工作——它们都生成并添加了SSH密钥。工作帐户有一个如何使用两个不同的ssh用户连接到GitLab?,git,ssh,gitlab,Git,Ssh,Gitlab,我有两个GitLab帐户——一个用于我的个人项目,一个用于工作——它们都生成并添加了SSH密钥。工作帐户有一个id\u rsa(因为这是我首先创建的),个人帐户有一个id\u rsa\u personal。我的~/ssh/config如下: Host gitlab-personal Preferredauthentications publickey User personalusername HostName gitlab.com IdentityFile ~/
id\u rsa
(因为这是我首先创建的),个人帐户有一个id\u rsa\u personal
。我的~/ssh/config
如下:
Host gitlab-personal
Preferredauthentications publickey
User personalusername
HostName gitlab.com
IdentityFile ~/.ssh/id_rsa_personal
Host gitlab-work
Preferredauthentications publickey
User workusername
HostName gitlab.com
IdentityFile ~/.ssh/id_rsa
然而,当我运行ssh-vvt时git@personalusername.gitlab.com
,我得到以下信息:
OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n 7 Dec 2017
debug1: Reading configuration data /home/personalusername/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "personalusername.gitlab.com" port 22
ssh: Could not resolve hostname personalusername.gitlab.com: Name or service not known
第四行(applyingoptions for*
)似乎表明ssh
忽略了我的两个配置设置,并选择了默认设置,即使用id\u rsa
。由于这是我的工作帐户,我无法克隆我的个人存储库,导致以下错误:
git clone git@gitlab.com:personalusername/personalproject.git personalprojecttest
Cloning into 'personalprojecttest'...
GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
还有一个类似的问题,答案是(),但这涉及到在Git config中指定用户名。我的问题是,我没有或想要一个全局Git配置,因为我在同一台机器上做个人和工作。我更喜欢本地Git配置(在./.Git/config中),但是,这个文件夹还不存在,所以我没有本地Git配置
我正在运行Ubuntu 18.04。您是否尝试了
ssh add~/.ssh/id\u rsa\u personal
?Booth密钥应该添加到ssh代理中。像往常一样,我在写下这个问题后不久就自己解决了这个问题。我用以下内容修改了我的~/ssh/config
文件:
Host gitlab.com
Preferredauthentications publickey
User personalusername@personalemailaddress.com
HostName gitlab.com
IdentityFile ~/.ssh/id_rsa_personal
Host gitlab.com
Preferredauthentications publickey
User workusername@workemailaddress.com
HostName gitlab.com
IdentityFile ~/.ssh/id_rsa
我只是简单地将用户personalusername
更改为使用电子邮件地址而不是用户名。在此之后,我成功地克隆了我的个人项目
还有ssh-vvvTgit@personalusername.gitlab.com
命令错误。正确的方法是ssh-vvtgit@gitlab.com,其输出中提到了两个键。这就是为什么我又给了git clone命令一次机会,只是为了检查一下。~/.ssh/config:
Host gitlab-personal
User git
HostName gitlab.com
IdentityFile ~/.ssh/id_rsa_personal
Preferredauthentications publickey
Host gitlab-work
User git
HostName gitlab.com
IdentityFile ~/.ssh/id_rsa
Preferredauthentications publickey
然后尝试ssh-vvvT gitlab personal
,ssh-vvt gitlab work
跑
我没有,但我认为这不是问题所在。它知道这两个密钥,但它只是无法确定为哪个用户使用哪个密钥。不是专家,但不久前,正如我所记得的,这是我设置多个身份的主要解决方案。
git clone gitlab-personal:personalusername/personalproject.git