【问题标题】:Git submodule public key permissions errorGit子模块公钥权限错误
【发布时间】:2022-10-13 13:51:59
【问题描述】:

我在 bitbucket 中托管了两个存储库 - 我有一个访问密钥设置,可用于单独克隆每个项目。存储库 A 具有存储库 B 作为子模块。

在 Windows 上...成功克隆 repo A 后,git submodule update --init 失败,原因如下:

Cloning into 'C:/Path/to/submodules/B'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@bitbucket.org:org/B.git' into submodule path 'C:/path/to/submodules/B' failed
Failed to clone 'submodules/B'. Retry scheduled

.gitmodules 设置如下

[submodule "submodules/B"]
    path = submodules/B
    url = git@bitbucket.org:org/B.git
...

如果我采用.gitmodules 中指定的 URL 并克隆该存储库,则它可以正常工作git clone git@bitbucket.org:org/B.git

似乎试图通过git submodule update --init 克隆的存储库无法看到/使用我添加的 ssh 访问密钥。

Git Submodule - Permission Denied 建议无效

  • 也许密钥需要刷新?不,该密钥非常适合下载所有其他存储库
  • 可能是密钥本身有问题,试试ssh -vT git@github.com将其更改为bitbucket.org 后,它工作得非常好,身份验证成功。
  • 我对 http 没有这个问题:/- 我也没有,我讨厌 ssh,但是,唉,这是必需的。

如何解决这个问题?或者我缺少什么配置?

我将在开发 docker 容器环境中执行此操作,因此不需要排除它。

这不像以下问题:

【问题讨论】:

  • 考虑使用 GIT_TRACE 和/或您拥有的任何系统跟踪工具,以查看子模块克隆是否出于某种原因使用与手动 git clone 不同的 ssh 实现。我认为这是最有可能的罪魁祸首:您的计算机上有两个不同的ssh 命令,其中一个在这里有效,而另一个无效。

标签: git ssh bitbucket git-submodules


【解决方案1】:

您需要确保克隆存储库时实际使用的密钥。
如果您的访问密钥不是您的默认密钥(例如在 ~/.ssh/id_rsa 中的默认密钥),那么您的子存储库的 URL 需要引用第二个密钥(访问密钥)

您可以更改remote URL of a submodule

git submodule set-url -- accessKey:me/mySubmoduleRepository

它将使用~/.ssh/config 文件:

Host accessKey
  hostname bitbucket.or
  User git
  IdentityFile ~/.ssh/myAccessKey

这样git submodule update --init 将使用直接引用您的访问密钥的 SSH URL:应该克隆子模块。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-03
    • 2013-03-18
    • 2014-03-18
    • 1970-01-01
    • 2013-04-29
    相关资源
    最近更新 更多