如何使用 SSH 密钥将 GitLab 存储库镜像到 GitHub?

Ste*_*fan 6 git github gitlab

GitLab 有镜像功能:

https://docs.gitlab.com/ee/user/project/repository/mirror/

并且GitHub不支持简单的密码认证。我试着跟随

https://meesvandongen.nl/posts/mirror-gitlab-github

使用目标网址

ssh://git@github.com:stefaneidelloth/mirror_demo.git
Run Code Online (Sandbox Code Playgroud)

SSH public key作为身份验证方法。

但是,我收到错误

Remote mirrors url is blocked: URI is invalid 
Run Code Online (Sandbox Code Playgroud)

来自亚搏体育实验室。

如果我指定目标网址

https://github.com/stefaneidelloth/mirror_demo.git
Run Code Online (Sandbox Code Playgroud)

我无法选择SSH public key身份验证方法。

=> 将 GitLab 项目镜像到 GitHub 项目(没有 GitLab PREMIUM 版本)的正确设置是什么?

编辑

第二个:需要替换为/.

GitHub 推荐:

在此输入图像描述

添加ssh://前缀是不够的。

错误的:ssh://git@github.com:stefaneidelloth/mirror_demo.git

github.com后仍需更换:

正确的:ssh://git@github.com/stefaneidelloth/mirror_demo.git

然后GitLab生成连接的SSH密钥,需要将其复制到GitHub项目设置(而不是用户设置),请参阅https://meesvandongen.nl/posts/mirror-gitlab-github

现在我收到下一个错误:

13:get remote references: create git ls-remote: exit status 128, stderr: "ssh connect to host github.com port 22: Connection timed out\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n".
Run Code Online (Sandbox Code Playgroud)

a)我是否需要指定 22 以外的端口?如何?我试过

ssh://git@github.com:443/stefaneidelloth/mirror_demo.git
Run Code Online (Sandbox Code Playgroud)

但这没有帮助。

b)我需要使用“手动输入主机密钥”吗?应该具体说明什么?我尝试使用

SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints

但这没有帮助。

c)我还尝试在用户设置中生成 GitHub AccessToken并将其应用于 GitLab 镜像设置的密码选项。我都试过了,https://还有git://网址。没有成功。

geo*_*sic 9

毕竟我让这个工作了。

  1. 是的,您需要手动编辑 git SSH URL,如您所示: ssh://git@github.com/stefaneidelloth/mirror_demo.git
  2. 选择 SSH 公钥作为身份验证方法。
  3. 然后点击镜像仓库按钮
  4. 复制生成的 SSH 密钥,如下所示: https: //meesvandongen.nl/posts/mirror-gitlab-github
  5. 然后需要将该密钥作为部署密钥添加到 GitHub 存储库,这是通过“设置”>“部署密钥”完成的(见下图)
  6. 单击镜像上的刷新。请注意,当我第一次这样做时,没有发生任何事情,没有错误,但也没有更新。我做了四次,仍然没有任何反应。大约27分钟后,更新发生了。

部署密钥

  • 对此稍作补充:您需要在“身份验证方法”下面的部分中将 SSH 密钥的用户名设置为 GitLab 上的“git”。没有别的办法了!(我不知道自你或 Mees 的帖子以来它是否发生了变化,因为你们都没有提到它,但它现在就在那里并困扰了我一段时间。) (2认同)