简体   繁体   English

在 gitlab 中有 2 个帐户的 ssh 不起作用

[英]ssh with 2 accounts in gitlab doesn't work

I'm trying to add 2 ssh keys in my pc to work with 2 gitlab accounts, I created 2 pair of keys and made this "config" file:我正在尝试在我的电脑中添加 2 个 ssh 密钥以使用 2 个 gitlab 帐户,我创建了 2 对密钥并制作了这个“配置”文件:

# Compte Perso
Host gitlab.com-perso
   HostName gitlab.com
   PreferredAuthentications publickey
   IdentityFile C:\Users\<path>\.ssh\id_rsa_perso

# Compte Pro
Host gitlab.com
   HostName gitlab.com
   PreferredAuthentications publickey
   IdentityFile C:\Users\<path>\.ssh\id_rsa

When I type ssh -T git@gitlab.com and ssh -T git@gitlab.com-perso , it works I have the output Wlecome to Gitlab, <username>!当我输入ssh -T git@gitlab.comssh -T git@gitlab.com-perso时,它会工作我有输出Wlecome to Gitlab, <username>! , but when I try to clone like this git clone git@gitlab.com-perso:<username>/<reponame>.git ,但是当我尝试像这样git clone git@gitlab.com-perso:<username>/<reponame>.git

it says它说

Unable to open connection:
Host does not existfatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I know the repo can be cloned because I already cloned it in another pc with ssh but I don't understand why this doesn't work please help me.我知道 repo 可以被克隆,因为我已经用 ssh 在另一台电脑上克隆了它,但我不明白为什么这不起作用请帮助我。 I have followed this to make my config file.我已经按照这个来制作我的配置文件。 (it's in french) (是法语)

First, you can add User git in each of your entries.首先,您可以在每个条目中添加User git That way, you can use gitlab.com-perso:<usernassh -T git@gitlab.com-persome>/<reponame>.git without the git@这样,您可以在没有git@的情况下使用gitlab.com-perso:<usernassh -T git@gitlab.com-persome>/<reponame>.git

Second, make sure ssh -T git@gitlab.com-perso return the right account, because if seems from your question both return the same username.其次,确保ssh -T git@gitlab.com-perso返回正确的帐户,因为如果从您的问题看来,两者都返回相同的用户名。

Host does not exist

Double check your host entry: gitlab.com-perso should use the right '-': you might have used a '—' (a long dash ) instead of the expected double hyphen (or hyphen-minus ).仔细检查您的主机条目:gitlab.com-perso 应该使用正确的“-”:您可能使用了“-”(长破折号)而不是预期的双连字符(或hyphen-minus )。

感谢@Lukasz Korbasiewicz 和@bdecaf,我在配置文件~/.ssh/config和环境变量中添加了IdentitiesOnly yesGIT_SSH=C:\Program Files\Git\usr\bin\ssh.exe并且它起作用了。

Quick google search search for your error message reveals that this problem may be related to "Little Snitch" software - if you use it disable and try again.快速谷歌搜索搜索您的错误消息显示此问题可能与“Little Snitch”软件有关 - 如果您使用它,请禁用并重试。

Also, on Windows machines you may need to modify windows system environment variables此外,在 Windows 机器上,您可能需要修改 Windows 系统环境变量

GIT_SSH=C:\Program Files\Git\usr\bin\ssh.exe

as you can see in this StackOverflow thread正如你在这个 StackOverflow 线程中看到的

If none of this works, there are couple of other ideas out there.如果这些都不起作用,那么还有其他一些想法。 It's a good idea to try at least couple of them and collect some more verbose output so we can help you better if still needed.至少尝试其中的几个并收集一些更详细的输出是个好主意,这样如果仍然需要我们可以更好地帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM