无法使用SSH从gitlab克隆

时间:2020-03-02 09:54:49

标签: ssh gitlab git-clone

我最近在ubuntu 18.04 LTS实例上安装了gitlab。我正在尝试从GitLab复制存储库。 我的ssh配置文件如下:

# ~/.ssh/config
User git
Hostname gitlab.com
IdentityFile ~/.ssh/id_ed25519
TCPKeepAlive yes
IdentitiesOnly yes

我在gitLab的SSH密钥中添加了ed25519公共密钥。当我尝试克隆存储库时,出现此问题-

$ git clone git@xxxx:root/test-project.git
Cloning into 'test-project'...
kex_exchange_identification: read: Connection reset by peer
fatal: Could not read from remote repository.

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

我在做什么错?我已经检查了互联网上的几个链接,但无法弄清楚自己做错了什么。

如果我使用http而不是ssh,则可以克隆并推送。

 git clone http://xxxx/root/test-project.git
Cloning into 'test-project'...
warning: You appear to have cloned an empty repository.

为什么http可以正常工作而不使用ssh?

2 个答案:

答案 0 :(得分:0)

您的ssh clone语句有误:git clone username git@example.com:root/test.git

该语句将尝试将名为username的存储库克隆到相对于当前路径git@example.com:root/test.git的位置。

您想忽略username

git clone git@example.com:root/test.git

答案 1 :(得分:0)

一种替代方法是使用sourcetree,它只需单击即可击中所有git clone和update命令,还可以为您的存储库和分支提供丰富的图形表示形式