Reputation: 41
I want to use SSH to automatically push my private Gitlab project to GitHub.com.
I configured ssh key with GitHub.com, and execute git clone [email protected]:my-project.git
successfuly.
sudo ssh -vT [email protected]
is ok
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
but use gitlab -> Mirroring repositories push failed.
Here are some of my Settings:
Git repository URL=ssh://[email protected]/username/project.git
Mirror direction=push
detect host keys
Authentication method=SSH public key
error:
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".
What's my problem?
Upvotes: 4
Views: 2980
Reputation: 680
First to get this out of the table, doing this via https won't work because of the following error:
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".
Following the official GitLab guide, one would assume ssh:// will work.
So I went to My GitLab repo > Settings > Repository > Mirroring repositories > Add new mirror
. I tried both url formats as the description provided by GitLab is ambiguous: ssh://[email protected]/myusername/project.git
and ssh://[email protected]/myusername/project.git
. I specified my GitHub username in the textfield. Then for authentication method I used SSH public key
. Clicked Mirror repository
. This created a new item in the Mirroring repositories
with three buttons for Copy SSH public key
, Update now
, and Remove
. I clicked the button to copy the SSH public key and went to the GitHub repository > Settings > Deploy keys > Add deploy key
and pasted the key into the key textbox. I titled my key as "Mirroring from GitLab" and checked Allow write access
and clicked Add key
. Then I went to GitLab Mirroring repositories again and clicked Update now
only to get the error below. It also does not work if I add the key to My GitHub profile > Settings > SSH and GPG keys > SSH keys > New SSH key
, still the same error. In both cases above, when adding the mirroring, I tried Detecting host keys automatically (the keys match those provided by GitHub), but to be sure, I also tried it with manually adding the key in that step, copying it from 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".
Then I found this link on how to Set up a push mirror from GitLab to GitHub that was linked in the official GitLab docs, but has different instructions (facepalm). So I followed that and if finally worked! The only downside is that the Fine-grained personal access tokens must have an expiration date (at the moment I could only set it max to a year). That means in a year, I will have to deal with this again. And I am sure I won't remember any of this happened :) For completeness, here are the steps:
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
It would be great if GitLab updated their docs.
Upvotes: 3
Reputation: 1323045
The GitLab Mirroring documentation includes:
SSH authentication is mutual:
- You must prove to the server that you’re allowed to access the repository.
- The server must also prove to you that it’s who it claims to be.
If you’re mirroring over SSH (using an ssh:// URL), you can authenticate using:
- Password-based authentication, just as over HTTPS.
- Public key authentication. This method is often more secure than password authentication, especially when the other repository supports deploy keys
So double-check those settings.
Upvotes: -3