我想使用 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".
我的问题是什么?
首先要将其从表中取出,通过 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 文档中链接,但有不同的说明(facepalm)。所以我遵循了这一点,如果终于成功了!唯一的缺点是细粒度个人访问令牌必须有一个到期日期(目前我只能将其最大设置为一年)。这意味着一年后,我将不得不再次处理这个问题。我确信我不会记得发生过任何这件事:)为了完整起见,以下是步骤:
创建一个新的 GitHub 存储库,用于镜像您的 GitLab 存储库。GitHub > Settings > Developer Settings > Personal access tokens > Fine-grained tokens > Generate new token
GitLab repo > Settings > Repository > Mirroring repositories > Add new mirror
https://github.com/user/repo
Mirror repository
Update now