我正在尝试在我的电脑中添加 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/