Git – Getting permission denied (public key) on gitlab

gitgitlabsshUbuntu

My problem is that I can't push or fetch from GitLab. However, I can clone (via HTTP or via SSH). I get this error when I try to push :

Permission denied (publickey) fatal : Could not read from remote repository

From all the threads I've looked, here is what I have done :

  • Set up an SSH key on my computer and added the public key to GitLab
  • Done the config –global for username and email
  • Cloned via SSH and via HTTP to check if it would resolve the issue
  • Done the ssh -T git@gitlab.com command

If you have any insight about how to resolve my issue, it would be greatly appreciated.

Best Answer

I found this after searching a lot. It will work perfectly fine for me.

  1. Go to "Git Bash" just like cmd. Right click and "Run as Administrator".
  2. Type ssh-keygen
  3. Press enter.
  4. It will ask you to save the key to the specific directory.
  5. Press enter. It will prompt you to type password or enter without password.
  6. The public key will be created to the specific directory.
  7. Now go to the directory and open .ssh folder.
  8. You'll see a file id_rsa.pub. Open it on notepad. Copy all text from it.
  9. Go to https://gitlab.com/-/profile/keys or
  10. Paste here in the "key" textfield.
  11. Now click on the "Title" below. It will automatically get filled.
  12. Then click "Add key".

Now give it a shot and it will work for sure.