Karthick S
Karthick S

Reputation: 391

Facing authentication failure with ssh when connecting to 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

Upvotes: 2

Views: 7787

Answers (1)

Karthick S
Karthick S

Reputation: 391

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
    

Upvotes: 8

Related Questions