I don’t know if this is the right place to ask this question but I tried everything looked through many forums and didn’t find my answer. I’m running GitLab on a virtual machine that has CentOS 7 on it and I set up the SSH keys but everytime i try to connect my repo with GitLab it asks for a password, I don’t know what more info to provide you with since im a newbie.
can you share the details how you did it? Which operating system are using for your Git client?
the OS is Linux CentOS 7, I used
ssh-keygen -t rsa -b 4096 -C "my-email"
to generate a ssh pair which I then copied to GitLab, then I made a test folder with git in it and I set origin with
git remote add origin git@ip-adress-of-my-virtual-machine:root/projectname
and when I tried to push it, it asks me for a password (I think it can’t find the public ssh key), I try to enter the password of GitLab but it says something like password denied. If you need any other information I will provide it just ask and thank you for trying to help.
Hi @MrRabbitz !!
Have you created more than 1 keys on this machine?
Even if you haven’t please make the following changes in order for the system to decide which one to use, we have to mention it in the ‘/etc/ssh/ssh_config’ file:
Host gitlab-example.com Preferredauthentications publickey IdentityFile ~/.ssh/id_rsa
Make sure that your (in above case is “gitlab-example.com”) is mapped correctly with an IPAddress in “/etc/hosts” file:
Also, make sure that the SSH key pair is generated at the default location “~/.ssh/id_rsa”.
Remove the previously created keys and generate new key pair using RSA and do not set the origin. Copy the id_rsa.pub (public key) on the GitLab account and then run the following command from the client machine on which the key pair is generated:
ssh -T firstname.lastname@example.org
do not forget to replace <gitlab-example.com> with your gitlab server name and then share the output of the above command.
I did try with more keys because I thought I might have copied them wrong or something but everytime I generated a new key pair i overwrote the id_rsa.
In my ‘/etc/ssh/ssh_config’ file I added the thing you mentioned but I use the IP address of the server (example 10.150.10.23) so I’m guessing there is no need to change the ‘/etc/hosts’ file.
The keys are generated in the ‘~/.ssh/id_rsa’, I made new ones and copied them to GitLab (I deleted the old ones from GitLab) and ran the command you wrote and the output was:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
Thank you for helping!
Just to make sure have you copied the contents of “~/.ssh/id_rsa” or “~/.ssh/id_rsa.pub” ?
Some troubleshooting steps could be:
- Just make sure you are able to ping the GitLab server at the IPAddress
- Restart the sshd.service
- Can you share the screenshot of the SSH Keys from your GitLab GUI
- A screenshot of the “ssh -T email@example.com”
I pinged it from the terminal in the virtual machine and from my PC and both worked fine, I restarted the sshd service the output is still the same:
And this is the output i got before I added the thing you mentioned in ‘/etc/ssh/ssh_config’ file:
Edit: I’m pretty sure I copied the keys correctly, especially from my PC where I used:
clip < ~/.ssh/id_rsa.pub
Also when I run:
`ssh -vvvT firstname.lastname@example.org`
I get this:
I don’t know if this helps you in any way or if you can read it.
It seems that there is some issue with how you are doing the entire process, I would request you to follow the following steps:
[It is assumed that GitLab(10.100.0.51) and client are two different machines. The SSH keys are generated on the “Client” machine]
- Delete the directory “~/.ssh” from both the client machine and the GitLab server
- Now, create the SSH Key pair on the client machine using the command ssh-keygen -t rsa -b 4096 -C "email@example.com"
- Define the IP Address in the “/etc/hosts” file on Client machine
- Make the changes in the ‘/etc/ssh/ssh_config’ file on the CLIENT machine:
Host gitlab-machine.com Preferredauthentications publickey IdentityFile ~/.ssh/id_rsa
Restart the sshd service on the CLIENT machine.
Now manually copy the contents of “~/.ssh/id_rsa.pub” file
[Make sure you copy the contents of id_rsa.pub file. Copy the data from ssh-rsa till the mail id(in this case user@firstname.lastname@example.org)
Open the GitLab’s GUI and copy the key in the SSH section.
Now, from the CLIENT machine, run the command ssh -T email@example.com
Make sure you follow ALL the steps and then share the results and the screenshots of the keys generated, keys copied and the output of the last command run.
I did everything you said, sorry I should have noted GitLab is on CentOS 7 and the client machine Windows 10.
This is the public key that it generated:
The screenshot of GitLab SSH:
And screenshot of output of the last command:
I put the URL as gitlab-machine.test. I hope this is everything you asked for.
did you setup a passphrase for the SSH key pair when asked? If so, don’t do that.
if anyone stumbles upon this with maybe the same problem, literally all I needed to do was run:
(sudo) gitlab-ctl reconfigure
No worries, every little step counts in learning new things. Maybe you’ll stay here for a while and try to help others too? Or leave a like on a reply showing your appreciation, and mark one as solution if it fits?
I want to say a big thank you. I ran into this problem and beat my head against a wall for a few hours until I came across this post. The trick that did it for me was adding the ssh_config file. Thank you for the concise resolution steps.