如何使用 GitLab 克隆 git 存储库

Posted

技术标签:

【中文标题】如何使用 GitLab 克隆 git 存储库【英文标题】:How to clone git repository with GitLab 【发布时间】:2017-03-04 12:57:15 【问题描述】:

我们的团队在 gitlab 上有一个 git 存储库。我在那里有一个帐户。我在一台计算机上创建了 ssh 密钥。现在我想将该仓库克隆到另一台机器上。在我的帐户中,我可以在“SSH 密钥”部分看到我的公钥,也可以在“帐户”部分看到我的私人令牌。起初我想在 smartgit 中使用现有密钥,但它不起作用,然后我创建了新密钥,将新公钥添加到我的帐户并尝试从 git bash 克隆,如下所示:

git clone  git@gitl.website.com:bla/bla.git

但它给了我

Cloning into 'bla'...
Permission denied (publickey).
fatal: Could not read from remote repository.

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

我什至尝试将公钥从我的 GitLab 帐户直接复制到 id_rsa.pub 文件。

那么我怎样才能克隆那个存储库呢?

已编辑

ssh -vvv git@gitl.website.com的最后几行

debug3: send packet: type 5
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /c/Users/Arthur/.ssh/id_rsa
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug1: Trying private key: /c/Users/Arthur/.ssh/id_dsa
debug3: no such identity: /c/Users/Arthur/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /c/Users/Arthur/.ssh/id_ecdsa
debug3: no such identity: /c/Users/Arthur/.ssh/id_ecdsa: No such file or directo                     ry
debug1: Trying private key: /c/Users/Arthur/.ssh/id_ed25519
debug3: no such identity: /c/Users/Arthur/.ssh/id_ed25519: No such file or direc                     tory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).

【问题讨论】:

“我什至尝试将公钥从我的 GitLab 帐户直接复制到 id_rsa.pub 文件中。”。这是一个非常糟糕的主意。反过来做。在您的计算机上,您需要私钥。从ssh -vvv git@gitl.website.com发布日志 Git bash 可能没有将私钥添加到您的 SSH 代理 编辑了一个带有日志的帖子。那么如何手动添加呢? 【参考方案1】:

去干净的白板。创建一个新密钥并对其进行处理。

    通过运行, ssh-keygen 并为其提供一个键名。

    复制keyname.pub并将密钥粘贴到gitlab帐户中。

    清除系统中已存在的所有剩余密钥,ssh-add -D

    添加刚才ssh-add <path_to_key>/keyname创建的密钥

现在,再试一次 git 命令。

【讨论】:

以上是关于如何使用 GitLab 克隆 git 存储库的主要内容,如果未能解决你的问题,请参考以下文章