SSH KEY:sudo git 克隆权限被拒绝

SSH KEY: sudo git clone permission denied

我在我的电脑 (ubuntu 16.04) 中创建了一个 public ssh 密钥,并将其链接到我的 gitlab.com 帐户。 我使用了 $ sudo git clone git@gitlab.com:XXXXXX/XXXXXX.git 并且出现了这个错误:

Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

所以我做了什么:我将 777 chmod 添加到我的 html 文件夹并仅使用命令 $ git clone git@gitlab.com:XXXXXX/XXXXXX.git 并成功创建了克隆。

谁能解释一下刚刚发生了什么??

由于您是 运行 git root,因此它可能尝试使用 root 的 ssh 密钥(如果有)而不是您的登录。

我在 GitLab 上遇到了同样的问题。我阅读了 GitHub 关于 ssh 密钥(生成、添加等)的文档,我可以成功完成。

GitHub document guide