1
votes

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

1
One of the answer do match the solution proposed here, but the question is semantically different. There the user is unable to access "./ssh" location. Here, the user is unaware that the custom named key needs special instructions for SSH to work. The user here has full control of .ssh director, so the fix is easy. I would recommend both the question be alive, it will benefit two different use cases experienced by the community.Karthick S

1 Answers

3
votes

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