Getting permission denied (public key) on gitlab

2019-01-21 06:37发布

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

Right now I want to punch my computer. If you have any insight about how to resolve my issue, it would be greatly appreciated.

10条回答
We Are One
2楼-- · 2019-01-21 07:11

if you are in linux or macox , just try this in terminal:

ssh-add -l

if it return nothing, try this:

ssh-add

it must create identity in ~/.ssh/id_rsa

after retry :

ssh-add -l

it must return your identity, so after retry to clone , it's must work

NB: don't forget to add your ssh key in your profile gitlab

thanks

查看更多
对你真心纯属浪费
3楼-- · 2019-01-21 07:12

I found this after searching alot. 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 .
  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.

查看更多
【Aperson】
4楼-- · 2019-01-21 07:12

make sure you are not running sudo git clone git@gitlab.com:project/somethiing.git, otherwise ssh will look in /root/.ssh instead of the key you uploaded ~/.ssh/id_rsa

查看更多
趁早两清
5楼-- · 2019-01-21 07:14

I added my ~/.ssh/id_rsa.pub to the list of known SSH Keys in my GitLab settings https://gitlab.com/profile/keys. That solved the problem for me. :-)

查看更多
登录 后发表回答