git - gitlab 中的 2 个帐户的 ssh 不起作用

标签 git ssh gitlab config

我正在尝试在我的电脑中添加 2 个 ssh key 以使用 2 个 gitlab 帐户,我创建了 2 对 key 并制作了这个“配置”文件:

# 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

当我输入ssh -T <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="45222c3105222c312924276b262a28" rel="noreferrer noopener nofollow">[email protected]</a>时和ssh -T <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8bece2ffcbece2ffe7eae9a5e8e4e6a6fbeef9f8e4" rel="noreferrer noopener nofollow">[email protected]</a> ,它有效我有输出 Wlecome to Gitlab, <username>! ,但是当我尝试像这样克隆 git clone <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed8a8499ad8a8499818c8fc38e8280c09d889f9e82" rel="noreferrer noopener nofollow">[email protected]</a>:<username>/<reponame>.git

它说

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.

我知道可以克隆该存储库,因为我已经使用 ssh 将其克隆到另一台电脑中,但我不明白为什么这不起作用,请帮助我。 我已关注this制作我的配置文件。 (法语)

最佳答案

首先,您可以添加 User git在您的每个条目中。这样,您可以使用 gitlab.com-perso:<usernassh -T <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e6818f92a6818f928a8784c885898bcb96839495898b83" rel="noreferrer noopener nofollow">[email protected]</a>>/<reponame>.git没有 git@

其次,确保ssh -T <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3a5d534e7a5d534e565b5814595557174a5f484955" rel="noreferrer noopener nofollow">[email protected]</a>返回正确的帐户,因为从您的问题看来,两者都返回相同的用户名。

Host does not exist

仔细检查您的主机条目:gitlab.com-perso 应该使用正确的“-”:您可能使用了“—”(a long dash )而不是预期的 double hyphen (或hyphen-minus)。

关于git - gitlab 中的 2 个帐户的 ssh 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72137128/

相关文章:

git - 为什么 GIT 不检测文件模式 644 和 664 之间的区别?

git - 将远程 repo url 从 https 更改为 ssh 安全吗?

eclipse - 无法通过SSH将裸Git项目导入Eclipse

android - 在 Android Lollipop 上通过 SSH 编译运行 ARM 汇编代码

Gitlab CI 将文件传送到远程服务器(rsync)

Gitlab-ci - 管道因无工作而失败

ruby-on-rails - 无法加载从 GitHub 获取的 Rails 应用; rake,rails 服务器不工作

Git,两个提交没有正确 merge 在一起

Gitlab CI没有缓存

git - 从 VSTS pull 请求中删除所需的批准者