Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facing authentication failure with ssh when connecting to gitlab

Tags:

git

ssh

gitlab

When trying to clone git account from gitlab using,

git clone [email protected]:username/project.git

facing the below error,

[email protected]: Permission denied (publickey). fatal: Could not read from remote repository.

The gitlab is registerd with my custom.pub public ssh key. Both the private and public ssh key of the windows client PC is stored in "C:/Users/username/.ssh".

How to fix this failure

like image 521
Karthick S Avatar asked Apr 09 '26 11:04

Karthick S


1 Answers

This answer for Windows. Should also apply to Linux machines with some modifications.

Since the ssh key was created with custom name 'custom.pub', ssh is unable to use that key. It instead by default looks for 'id_ecdsa'/'id_rsa' named key files. Here are the steps to fix such authentication errors,

  1. First check what key ssh is currently trying to use for gitlab: go to cmd, ssh -v [email protected]
  2. If it does not spit out the key you have registered with gitlab, then you should tell ssh to pick the right key. This can be done with settings in .ssh/config file
  3. Open .ssh/config file and make following changes,

    Host *gitlab.com

      IdentityFile <your_custom_key_path>/custom_key
    
like image 193
Karthick S Avatar answered Apr 10 '26 23:04

Karthick S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!