Git 子模块公钥权限错误

问题描述 投票:0回答:3

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

在 Windows 上...成功克隆存储库 A 后,

git submodule update --init
由于以下原因失败:

Cloning into 'C:/Path/to/submodules/B'...
[email protected]: 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 '[email protected]: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 = [email protected]:org/B.git
...

如果我采用

.gitmodules
中指定的 URL 并克隆该存储库,它就可以完美工作
git clone [email protected]:org/B.git

尝试通过

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

Git 子模块 - 权限被拒绝建议不起作用

  • 也许密钥需要刷新?不,密钥可以完美地下载所有其他存储库
  • 也许密钥本身有问题,请尝试
    ssh -vT [email protected]
    更改为
    bitbucket.org
    后,它工作得很好,身份验证成功。
  • 我的 http :/ 没有遇到这个问题 - 我也没有,而且我讨厌 ssh,但是,唉,这是必需的。

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

我将在开发 Docker 容器环境中执行此操作,因此不需要排除这种情况。

这不像以下问题:

git ssh bitbucket git-submodules
3个回答
0
投票

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

您可以更改子模块的远程 URL:

git 子模块 set-url -- accessKey:me/mySubmoduleRepository

它将使用一个

~/.ssh/config
文件:

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

这样,

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


0
投票

使用 https 而不是 ssh 克隆子模块可能会更容易:在 .gitmodule 中从

[email protected]:
更改为
https://bitbucket.org/
,然后

git submodule sync
git submodule update --init

参见 Git 子模块:[email protected]:权限被拒绝(公钥)。致命:无法从远程存储库读取


0
投票

我也遇到了同样的问题,这是因为 MING 终端没有使用与 Sourcetree UI 相同的身份验证方法。

简短的回答,在运行之前将其输入终端

git submodule update --init

git config credential.helper sourcetree

我在这里找到了这个答案: https://jira.atlassian.com/browse/SRCTREE-2029

注意: 您必须确保您的“父”存储库设置为在 Sourcetree 中使用 ssh。您可以通过单击 Repository->Repository Settings 并查看源路径来检查这一点。如果此开头是“http://”,那么您需要更改它,否则此答案将不起作用。 这里有更多信息:如何将 Sourcetree 设置为在克隆远程存储库时默认使用 ssh 路径?

© www.soinside.com 2019 - 2024. All rights reserved.