Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save nguyentamvinhlong/d3c9e15a687179a639704c21c5291f39 to your computer and use it in GitHub Desktop.

Select an option

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/

@terdelyi

terdelyi commented Jan 8, 2018

Copy link
Copy Markdown

TCPKeepAlive yes and IdentitiesOnly yes saved my time as well when I tried to clone a repository into two different directories on the same server. Thanks!

@kslays

kslays commented Jan 10, 2018

Copy link
Copy Markdown

The configuration file should be named "config", and write permission should be for the user alone, as described here: https://serverfault.com/questions/253313/ssh-returns-bad-owner-or-permissions-on-ssh-config

@charlesfranciscodev

Copy link
Copy Markdown

thank you, this saved me!

@MxRay

MxRay commented Apr 4, 2018

Copy link
Copy Markdown

Thank you, it worked for me also

@ngminhtrung

Copy link
Copy Markdown

Thank you, this worked for me as well.

@TzuHanLiang

Copy link
Copy Markdown

Thank you so much!

@pete-willard

Copy link
Copy Markdown

You magnificent bastard! ๐Ÿบ

@LaP-SM

LaP-SM commented Jun 27, 2021

Copy link
Copy Markdown

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

@simxn1

simxn1 commented Aug 23, 2021

Copy link
Copy Markdown

thank you

@rgirasegit

Copy link
Copy Markdown

thank you

@Skifry

Skifry commented Nov 20, 2021

Copy link
Copy Markdown

thank you

@er-deepak-ram

Copy link
Copy Markdown

What is the name and extension of the config file?

@arohiabhilasha

Copy link
Copy Markdown

This saved much time. Thanks!

@Skateboardb

Copy link
Copy Markdown

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
Copy Markdown

Excellent, thanks !

@steveMQ

steveMQ commented Jul 23, 2022

Copy link
Copy Markdown

Thanks, this was driving me batshit lol

@LR-Argentino

Copy link
Copy Markdown

Thanks is working for me! ๐ŸŽ‰

@MityaPM

MityaPM commented Apr 8, 2023

Copy link
Copy Markdown

You're the best. Thanks a lot!

@gamboak

gamboak commented Apr 17, 2023

Copy link
Copy Markdown

Amazing, thank you lots!

@aamorozov

Copy link
Copy Markdown

Thank you!

@AlfredMisse

Copy link
Copy Markdown

Thank you very much

@qqcvd

qqcvd commented May 5, 2025

Copy link
Copy Markdown

Thank you very much

@kaustubh0010

Copy link
Copy Markdown

Thank you good sir

@Rodney-Web

Copy link
Copy Markdown

Thank you good sir

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