【问题标题】:How to clone private group's GitLab repository without typing password?如何在不输入密码的情况下克隆私人组的 GitLab 存储库?
【发布时间】:2022-01-12 19:22:52
【问题描述】:

在 GitLab 中,我拥有一个组,并且在这个组中我有一个私有存储库。 它的网址如下所示:https://gitlab.com/groupname/reponame

在我的机器上,我有一个 ssh 密钥对 id_rsa_gitlabid_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。

标签: gitlab ssh-keys git-clone


【解决方案1】:

看来,根据this answer,您可以在两种类型的网址之间进行选择

  • 无论是架构,在这种情况下ssh://git@gitlab.com/group/repo.git
  • 或“scp-like”,没有架构,git@gitlab.com:group/repo.git(example from gitlab docs)

您必须只选择其中一个,混合它们很可能会导致问题(这就是所讨论的 ssh url 发生的情况)。

还请注意,如果您更喜欢类似 scp 的 url,并且您必须指定端口,您可能希望将端口放入 .ssh/config 文件而不是 url,like this(我个人未能直接在 url 中找出正确的端口位置但配置文件没有问题)。

【讨论】:

  • 为避免混淆,“scp-like”语法为:git@gitlab.com:group/repo.gituser_1 的语法特定于您 use different accounts on a single GitLab instance 时的情况。由于这不是标准的,也许您可​​以编辑您的问题,因为这首先让我在文档中感到困惑。谢谢
  • @Paloha 已更新!
猜你喜欢
  • 1970-01-01
  • 2020-04-20
  • 2015-07-24
  • 1970-01-01
  • 2014-10-30
  • 2022-01-23
  • 1970-01-01
  • 2016-02-26
  • 1970-01-01
相关资源
最近更新 更多