gitlab镜像仓库推送到远程仓库

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

我想使用 SSH 自动将我的私有 Gitlab 项目推送到 GitHub.com。 我在 GitHub.com 配置了 ssh 密钥,并执行

git clone [email protected]:my-project.git
成功。
sudo ssh -vT [email protected]
还可以

debug1: Authentication succeeded (publickey).
Authenticated to github.com ([20.205.243.166]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi muxianliangqin! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3572, received 2912 bytes, in 0.6 seconds
Bytes per second: sent 6123.4, received 4992.0
debug1: Exit status 1

但使用 gitlab -> 镜像存储库推送失败。
以下是我的一些设置:

Git repository URL=ssh://[email protected]/username/project.git
Mirror direction=push
detect host keys
Authentication method=SSH public key

错误:

13:get remote references: create git ls-remote: exit status 128, stderr: "[email protected]: Permission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n".

我的问题是什么?

这是我在 GitHub 上的设置 enter image description here

这是我在 gitlab 上的设置。 enter image description here

ssh gitlab repository mirroring
2个回答
0
投票

以下方法无效

首先要将其从表中取出,通过 https 执行此操作将不起作用,因为出现以下错误:

13:push to mirror: git push: exit status 128, stderr: "remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https://github.com/paloha/faket.git/'\n".

按照官方 GitLab 指南,人们会认为 ssh:// 可以工作。 所以我去了

My GitLab repo > Settings > Repository > Mirroring repositories > Add new mirror
。我尝试了两种 url 格式,因为 GitLab 提供的描述不明确:
ssh://[email protected]/myusername/project.git
ssh://[email protected]/myusername/project.git
。我在文本字段中指定了我的 GitHub 用户名。然后对于身份验证方法,我使用了
SSH public key
。单击
Mirror repository
。这会在
Mirroring repositories
中创建一个新项目,其中包含
Copy SSH public key
Update now
Remove
三个按钮。我单击按钮复制 SSH 公钥,然后转到
GitHub repository > Settings > Deploy keys > Add deploy key
并将密钥粘贴到密钥文本框中。我将密钥命名为“从 GitLab 镜像”并选中
Allow write access
并单击
Add key
。然后我再次访问 GitLab 镜像存储库并单击
Update now
却收到以下错误。如果我将密钥添加到
My GitHub profile > Settings > SSH and GPG keys > SSH keys > New SSH key
,它也不起作用,仍然是相同的错误。在上面的两种情况下,在添加镜像时,我尝试自动检测主机密钥(密钥与 GitHub 提供的密钥匹配),但可以肯定的是,我还尝试了在该步骤中手动添加密钥,从 GitHub 复制它. 13:get remote references: create git ls-remote: exit status 128, stderr: "*****@github.com Permission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n".

使用细粒度个人访问令牌的方法有效!

然后我找到了

这个关于如何设置从 GitLab 到 GitHub 的推送镜像的链接

,它在官方 GitLab 文档中链接,但有不同的说明(facepalm)。所以我遵循了这一点,如果终于成功了!唯一的缺点是细粒度个人访问令牌必须有一个到期日期(目前我只能将其最大设置为一年)。这意味着一年后,我将不得不再次处理这个问题。我确信我不会记得发生过任何这件事:)为了完整起见,以下是步骤:

创建一个新的 GitHub 存储库,用于镜像您的 GitLab 存储库。
  1. 前往
  2. GitHub > Settings > Developer Settings > Personal access tokens > Fine-grained tokens > Generate new token
  3. 限制令牌仅适用于您的新存储库,并在存储库权限中为其授予内容的读写访问权限。
  4. 生成令牌并复制它。
  5. 前往
  6. GitLab repo > Settings > Repository > Mirroring repositories > Add new mirror
  7. 粘贴 GitHub 存储库的完整 https URL,例如
  8. https://github.com/user/repo
  9. 填写您的 GitHub 用户名
  10. 作为密码,使用您之前复制的细粒度令牌
  11. 点击
  12. Mirror repository
  13. 点击
  14. Update now
  15. 
    
  16. 如果 GitLab 更新他们的文档那就太好了。


-3
投票
GitLab 镜像文档

包括:

SSH 身份验证是相互的:

您必须向服务器证明您有权访问存储库。
  • 服务器还必须向您证明它就是它所声称的身份。
  • 如果您通过 SSH 进行镜像(使用 ssh:// URL),则可以使用以下方式进行身份验证:

基于密码的身份验证,就像通过 HTTPS 一样。
  • 公钥认证。此方法通常比密码身份验证更安全,特别是当其他存储库支持部署密钥时
因此请仔细检查这些设置。

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