Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • 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 [email protected]: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 [email protected]:your_account/user_repo.git

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

@santiagosantamaria
Copy link

Excellent, thanks !

@steveMQ
Copy link

steveMQ commented Jul 23, 2022

Thanks, this was driving me batshit lol

@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!

@AlfredMisse
Copy link

Thank you very much

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