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/

@pete-willard
Copy link

You magnificent bastard! 🍺

@LaP-SM
Copy link

LaP-SM commented Jun 27, 2021

You are a life saver, I wasted a whole day until I come across this!!! Brilliant.

@simxn1
Copy link

simxn1 commented Aug 23, 2021

thank you

@rgirasegit
Copy link

thank you

@Skifry
Copy link

Skifry commented Nov 20, 2021

thank you

@er-deepak-ram
Copy link

What is the name and extension of the config file?

@arohiabhilasha
Copy link

This saved much time. Thanks!

@Skateboardb
Copy link

THANK YOU!!!! I don't understand why the directions given on gitlab for creating the config file seem to generate this error, but I'm glad you found a fix.

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

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