【问题标题】:Need help cloning a GitHub repository because of public key issues由于公钥问题需要帮助克隆 GitHub 存储库
【发布时间】:2017-11-06 01:08:29
【问题描述】:

我正在尝试在一台服务器中克隆一个私有 GitHub 存储库,我试图在虚拟机上启动并运行该存储库。

无论我做什么,我都会收到以下错误:

Permission denied (publickey).
fatal: Could not read from remote repository.

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

我已经尝试了很多东西。对于初学者,我通过关注GitHub's tutorial 确保我正确地制作了我的 rsa 密钥。我还确定我在 ~/.ssh/id_rsa.pub 找到的公共 rsa 密钥已正确复制到我的 GitHub 帐户的 ssh 密钥中。

我在~/.ssh/config 的配置文件如下所示:

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa

我尝试克隆一个公共存储库和一个私有存储库,但都不起作用。

当我去克隆存储库时,我正在执行以下命令:

sudo git clone git@github.mit.edu:<GitHub Name>/<Repo Name>.git

如果我在没有sudo 的情况下执行命令,则会收到以下错误:

fatal: could not create work tree dir '<Repo Name>'.: Permission denied

当我执行所有这些操作时,我处于 ​​Python 虚拟环境中。这有什么不同吗?

我一直在阅读与此问题相关的 Stack Overflow 帖子,但它们都没有帮助我解决我的问题。

任何帮助将不胜感激!谢谢!

【问题讨论】:

  • 不要使用sudo
  • 所以当我不使用 sudo 时,我会收到错误 fatal: could not create work tree dir '&lt;Repo Name&gt;'.: Permission denied

标签: linux git github ssh


【解决方案1】:

您使用的是sudo,所以Git 使用的是用户root 的ssh 密钥。

要完成这项工作,您必须在没有 sudo 的情况下调用 git。

所以当我不使用 sudo 时,我会收到致命错误:无法创建工作 树目录'cardlearning'。:权限被拒绝

确保当前用户在您正在执行克隆的目录中具有写权限。

您无法克隆到现有目录,因此您可以:

$ sudo mkdir tmp
$ sudo chown $USER: tmp
$ git clone git@github.mit.edu:<GitHub Name>/<Repo Name>.git tmp/cardlearning
$ mv tmp/cardlearning ./cardlearning
$ rmdir tmp

【讨论】:

  • 当我这样做时,我似乎走得更远了,但我在~/.ssh/config 中的config 文件周围出现了一些错误,即:/home/agaidis/.ssh/config: line 2: Bad configuration option: addkeystoagent /home/agaidis/.ssh/config: line 3: Bad configuration option: usekeychain /home/agaidis/.ssh/config: terminating, 2 bad configuration options fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
  • 从您的 ~/.ssh/config 文件中删除无效选项。删除粘贴在您问题中的所有四个指令应该没问题。
  • 谢谢!这真的救了我。
【解决方案2】:

检查您的用户是否有权写入您所在的目录。

或执行

git clone git@github.mit.edu:<GitHub Name>/<Repo Name>.git ~/myRepo

将其放在主目录的myRepo 子目录中。

在使用~ 引用路径时,请勿使用 sudo 编辑您的 ssh 配置,因为您最终可能会编辑 root 用户的 ssh 首选项而不是您的用户。同样不要使用sudo 克隆存储库,因为它会尝试使用root 用户的ssh 密钥进行连接。

【讨论】:

    猜你喜欢
    • 2018-04-01
    • 2021-12-31
    • 2014-01-10
    • 2011-11-22
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    相关资源
    最近更新 更多