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

huangapple go评论76阅读模式
英文:

How to mirror a GitLab repository to GitHub using SSH keys?

问题

GitLab具有镜像功能:

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

而GitHub不支持简单密码身份验证。我尝试遵循

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

使用目标URL

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项目镜像到GitHub项目(不使用GitLab的PREMIUM版)?

编辑

第二个:需要替换为/

GitHub建议的:

如何使用SSH密钥将GitLab存储库镜像到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".

**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。没有成功。

英文:

GitLab has a mirror feature:

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

and GitHub does not support simple password authentication. I tried to follow

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

Using the target url

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

and SSH public key as authentication method.

However, I get an error

Remote mirrors url is blocked: URI is invalid 

from GitLab.

If I specify the target url

https://github.com/stefaneidelloth/mirror_demo.git

I am not able to select SSH public key as authentication method.

=> What are the right settings to mirror a GitLab project to a GitHub project (without PREMIUM edition of GitLab)?

Edit

The second : needs to be replaced with a /.

Suggested by GitHub:

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

Adding ssh:// prefix is not enough.

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

Still need to replace : after github.com:

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

Then GitLab generates the SSH key for the connection and one needs to copy it to the GitHub project settings (not the user settings), see https://meesvandongen.nl/posts/mirror-gitlab-github

Now I get the next error:

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) Do I need to specify a different port than 22? How? I tried

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

but that did not help.

b) Do I need to use "Input host keys manually"? What should be specified? I tried to use

SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s

from

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

but that did not help.

c) I also tried to generate a GitHub AccessToken in the user settings and apply it for the password option of the GitLab Mirror settings. I tried both, https:// and git:// urls. No success.

答案1

得分: 3

我最后成功使这个工作了。

  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分钟后,更新发生了。

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

英文:

I got this to work after all.

  1. Yes, you need to manually edit the git SSH URL, as you have shown:
    ssh://git@github.com/stefaneidelloth/mirror_demo.git
  2. Select SSH public key as authentication method.
  3. Then click mirror repository button
  4. Copy the SSH key generated as shown here: https://meesvandongen.nl/posts/mirror-gitlab-github
  5. The key then needs to be added as a Deploy Key to the GitHub Repo, which is done from Settings > Deploy Keys (see figure below)
  6. Click refresh on the mirror. Note that when I first did this, nothing happened, no errors, but also no update. I did it four times and still nothing happened. Then about 27 minutes later, the update happened.

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

答案2

得分: 0

"ssh connect to host github.com port 22: Connection timed out" 表示有东西阻止了对 github.com 的 22 端口的连接,可能是代理或防火墙。GitHub 有一个单独的主机名(不是 github.com),用于处理 SSH 流量,它使用了一个不太容易被阻止的端口;你需要使用以下 URL 连接:ssh://git@ssh.github.com:443/stefaneidelloth/mirror_demo.git

英文:

"ssh connect to host github.com port 22: Connection timed out" suggests that something is blocking port 22 for github.com - perhaps a proxy or firewall. GitHub has a separate hostname (not github.com) for handling SSH traffic over a rarely-blocked port; your URL for that would need to be ssh://git@ssh.github.com:443/stefaneidelloth/mirror_demo.git.

huangapple
  • 本文由 发表于 2023年6月12日 19:38:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76456288.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定