Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save nguyentamvinhlong/d3c9e15a687179a639704c21c5291f39 to your computer and use it in GitHub Desktop.
Save nguyentamvinhlong/d3c9e15a687179a639704c21c5291f39 to your computer and use it in GitHub Desktop.
Gitlab Permission denied (publickey) error SOLVED

Gitlab Permission denied (publickey) error SOLVED

Permission denied (publickey)

Seems a very common error in Gitlab.com or any Gitlab implementation. Last night I spend 4/5 hours without sleeping to solve the error.

Cloning into 'server'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
vagrant@advocado:/var/www/test/advo$ sudo git clone git@gitlab.com:arifulhaque/server.git
Cloning into 'server'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

This is not first time I am adding SSH Key to Gitlab. My other VM have it in 2 different gitlab implementations but this new VM is not working. Before I get the error, I created a SSH Key and added the Public Key to Gitlab.com All worked fine, but I couldn’t clone any repo from account through ssh git.

I guess maybe I read almost all the solution over internet but none worked in my case. So, how did I finally solved this? Very Easy! Solution

Step 1: Added a config file in ~/.ssh/ folder which looks like

Host gitlab.com
       User git
       Hostname gitlab.com
       IdentityFile ~/.ssh/id_rsa_gitlab
       TCPKeepAlive yes
       IdentitiesOnly yes

Step 2: Just clone the git repo WITHOUT sudo.

git clone git@gitlab.com:your_account/user_repo.git

source: http://www.arifulhaque.com/gitlab-permission-denied-publickey-error-solved/

@LR-Argentino
Copy link

Thanks is working for me! 🎉

@MityaPM
Copy link

MityaPM commented Apr 8, 2023

You're the best. Thanks a lot!

@gamboak
Copy link

gamboak commented Apr 17, 2023

Amazing, thank you lots!

@aamorozov
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment