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

6
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

以及使用SSH公钥作为身份验证方法。

然而,我遇到了一个错误。

Remote mirrors url is blocked: URI is invalid 

从GitLab中。
如果我指定目标URL
https://github.com/stefaneidelloth/mirror_demo.git

我无法选择“SSH公钥”作为认证方式。

=> 如何在没有GitLab的高级版的情况下将GitLab项目镜像到GitHub项目的正确设置是什么?

编辑

第二个:需要替换为/

由GitHub建议:

enter image description here

只添加 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".

a) 我需要指定一个与22不同的端口吗?如何操作?我已经尝试过了

ssh://git@github.com:443/stefaneidelloth/mirror_demo.git

但是那并没有帮助。
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://的URL,但都没有成功。


我也试过这个。无法使其工作。一旦将生成的 SSH 密钥添加到 GitHub 仓库作为具有写入访问权限的部署令牌,我就解决了你遇到的错误。然而,尽管不再显示错误,GitHub 仓库没有得到更新,刷新操作似乎会失败而不显示任何错误。 - geoidesic
2个回答

7
我终于搞定了这个问题。
  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 Repo的部署密钥,可以在设置中找到部署密钥选项(见下图)。
  6. 点击刷新镜像。请注意,当我第一次尝试时,没有任何错误提示,但也没有更新。我重试了四次,仍然没有反应。然后大约27分钟后,更新才生效。

Deploy Keys


稍微补充一下:在GitLab上,您需要将SSH密钥的用户名设置为git,在“身份验证方法”下面的部分。其他任何设置都无效!(我不知道自从您或Mees的帖子以来是否有所更改,因为您们两个都没有提到它,但现在已经有了,并且让我困惑了一段时间。) - undefined

2
"ssh连接到主机github.com的端口22超时"表明有些东西阻止了github.com的22号端口,可能是代理或防火墙。GitHub有一个单独的主机名(不是github.com),用于处理SSH流量,该端口很少被阻塞;您需要使用以下URL:ssh://git@ssh.github.com:443/stefaneidelloth/mirror_demo.git

谢谢@geoidesic和**@jim-redmond** - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接