【发布时间】:2022-01-12 19:22:52
【问题描述】:
在 GitLab 中,我拥有一个组,并且在这个组中我有一个私有存储库。
它的网址如下所示:https://gitlab.com/groupname/reponame。
在我的机器上,我有一个 ssh 密钥对 id_rsa_gitlab 和 id_rsa_gitlab.pub。
我在 GitLab 设置中添加了公钥。我在~/.ssh/config 中添加了以下代码:
# GitLab.com
Host gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitlab
我已经使用ssh -T git@gitlab.com as in the docs 测试了通信是否正常。
现在,我想克隆我小组的私人仓库。但不幸的是,如果不手动输入我的 GitLab 用户名和密码(不是 SSH 密钥的密码,而是我的 GitLab 帐户的密码),以下所有操作均无效。
# Asks for username and pass and then clones successfully
git clone https://gitlab.com/group/repo
git clone https://gitlab.com/group/repo.git
git clone https://git@gitlab.com/group/repo
git clone https://<myGitLabUser>@gitlab.com/group/repo
# Asks only for password and then clones successfully
git clone https://<myGitLabUser>@gitlab.com/group/repo.git
# Asks only for password and then fatal: Authentication failed for '...'
git clone https://git@gitlab.com/group/repo.git
# fatal: repository '...' does not exist
git clone git@gitlab.com/group/repo
git clone git@gitlab.com/group/repo.git
git clone <myGitLabUser>@gitlab.com/group/repo
git clone <myGitLabUser>@gitlab.com/group/repo.git
我做错了什么?这不可能吗?
【问题讨论】:
-
以防万一-您是否有机会将 gitlab 配置为可通过任何特定端口访问?在这种情况下,您还必须指定端口
-
不,没有自定义端口。
-
你不应该把 ssh:// 方案放在回购路径之前吗?比如“git clone ssh://git@gitlab.com/group/repo.git”?
-
@FyodorVolchyok 哇,这行得通。谢谢!您会将其添加为答案以便我接受吗?顺便说一句,在使用 https 方法后,我也无法 git push。它询问用户名和密码,然后返回错误。我发现问题出在
git remote中,它设置为origin https://gitlab.com/group/repo而不是origin git@gitlab.com:group/repo.git。我使用stackoverflow.com/a/2432799/8691571 对其进行了更改,现在一切都像魅力一样。 -
很高兴它有帮助 :) 不会撒谎 - 所有这些 ssh:// 的东西总是一个带有路径、键、配置等的 PITA。