Can't push from git to gitlab via SSH (asks for password)?

,

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.

Hi,

can you share the details how you did it? Which operating system are using for your Git client?

Cheers,
Michael

Hi,

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:

192.168.10.1 gitlab-example.com

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 git@gitlab-example.com

do not forget to replace <gitlab-example.com> with your gitlab server name and then share the output of the above command.

Thanks!

1 Like

Hi @paramveer.singh,

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:

  1. Just make sure you are able to ping the GitLab server at the IPAddress
  2. Restart the sshd.service
  3. Can you share the screenshot of the SSH Keys from your GitLab GUI
  4. A screenshot of the “ssh -T git@gitlab-example.com

Thanks!

1 Like

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:

2963eb6d2ad3d8e883e217abb80b5a62

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 git@10.100.0.51`

I get this:

3

I don’t know if this helps you in any way or if you can read it.

Hi!

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]

  1. Delete the directory “~/.ssh” from both the client machine and the GitLab server
  2. Now, create the SSH Key pair on the client machine using the command ssh-keygen -t rsa -b 4096 -C "user@gitlab-example.com"
  3. Define the IP Address in the “/etc/hosts” file on Client machine

10.100.0.51 gitlab-machine.com

  1. 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.

  1. 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@gitlab@gitlab-example.com)

  2. Open the GitLab’s GUI and copy the key in the SSH section.

  3. Now, from the CLIENT machine, run the command ssh -T git@gitlab-machine.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.

1 Like

Hi,

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.

Thank you!

Hi,

did you setup a passphrase for the SSH key pair when asked? If so, don’t do that.

Cheers,
Michael

Hi,

if anyone stumbles upon this with maybe the same problem, literally all I needed to do was run:

(sudo) gitlab-ctl reconfigure

@dnsmichi and @paramveer.singh thank you so much for the help and sorry for wasting your time.

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? :slight_smile:

Cheers,
Michael

1 Like

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.

2 Likes