In GitLab, I own a group, and within this group I have a private repository.
It's url looks like this: https://gitlab.com/groupname/reponame
.
On my machine, I have an ssh key pair id_rsa_gitlab
& id_rsa_gitlab.pub
.
I have added the public key in GitLab settings. And I have added the following code in my ~/.ssh/config
:
# GitLab.com
Host gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitlab
I have tested that the communication works using ssh -T [email protected]
as in the docs.
Now, I would like to clone my group's private repo. But unfortunately, none of the following works without manually typing my GitLab username and password (not the password of the SSH key, but the password for my GitLab account).
# Asks for username and pass and then clones successfully
git clone https://gitlab.com/group/repo
git clone https://gitlab.com/group/repo.git
git clone https://[email protected]/group/repo
git clone https://<myGitLabUser>@gitlab.com/group/repo
# Asks only for password and then clones successfully
git clone https://<myGitLabUser>@gitlab.com/group/repo.git
# Asks only for password and then fatal: Authentication failed for '...'
git clone https://[email protected]/group/repo.git
# fatal: repository '...' does not exist
git clone [email protected]/group/repo
git clone [email protected]/group/repo.git
git clone <myGitLabUser>@gitlab.com/group/repo
git clone <myGitLabUser>@gitlab.com/group/repo.git
What am I doing wrong? Is this not possible?
It appears that according to this answer you could choose between two types of urls
ssh://[email protected]/group/repo.git
in this case[email protected]:group/repo.git
(example from gitlab docs)You have to choose only one of them and mixing them will most likely lead to problems (that's what happened with ssh urls at question).
Also note that if you prefer scp-like urls AND you have to specify port you probably want to put port into .ssh/config
file instead of url, like this (I personally failed to figure out correct port placement directly in url but config file worked without issues).