Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Permission denied (publickey) fatal - Could not read from remote repository. while cloning Git repository

Tags:

git

git-clone

People also ask

How do I fix SSH permission denied publickey?

If you want to use a password to access the SSH server, a solution for fixing the Permission denied error is to enable password login in the sshd_config file. In the file, find the PasswordAuthentication line and make sure it ends with yes . Find the ChallengeResponseAuthentication option and disable it by adding no .


For people that come here that are just trying to get the repository but don't care about the protocol (ssh / https), you might just want to use https instead of ssh (if it's supported).

So for example you use

git clone https://github.com/%REPOSITORYFOLDER%/%REPOSITORYNAME%.git

instead of

git clone [email protected]:%REPOSITORYFOLDER%/%REPOSITORYNAME%.git

Note that GitHub deprecated password authentication (https login) for private repositories due to it not keeping up with the latest security standards.

Note also that beginning March 1, 2022, Bitbucket users will no longer be able to use their Atlassian account password with git over https, but instead need to use Bitbucket app passwords.


If there is still issue around access after creating SSH and adding it in your Bitbucket account or wherever, you need to do the following in terminal on GitBash, OSX or Linux:

# Lists already added identities (‘ssh keys’)
ssh-add -l

Then, if you don't see your key listed, add it with the following (replace identity with its real name):

# Add a new identity
ssh-add ~/.ssh/identity

This worked for me.


It looks like a permissions issue - not a Windows 7 issue.

Your ssh key is not authorised - Permission denied (publickey).

You need to create a public ssh key and ask the administrator of the Git repository to add the ssh public key

Information on how to do this: Saving ssh key fails


I faced the same problem with GitHub. Here's how to solve it!

  1. Generate a SSH key on your computer as described here : Generating SSH keys.
  2. Login your GitHub account: GitHub Login.
  3. In your account, add the newly generated SSH Key: My account SSH keys.
  4. Try again to git clone the project.

I've had this issue on a Mac - while I setup SSH correctly to access my Git repository, after restart (and some time the Mac was on a standoff), all my credentials were removed. Apparently, for some reason the pub key was set to 644 which caused it to be removed from the keychain. To readd:

  • chmod 600 the public key
  • ssh-add ~/.ssh/[your private key] - this should display that identity has been added. The key file you want is the one without the .pub extension.
  • ssh-add -l should show you newly added identity

edit: apparently MacOS has tendency of removing keys - after downloading the High Sierra update (but I've not installed it yet) my key has been removed and I've had to add it again via ssh-add


For me, when i wanted to clone from my repository, i had the same message noticed before "Permission denied (publickey) fatal: Could not read from remote repository". The solution for my case is to not use sudo before clone That's it.


I also faced the same issue. I did the following and it worked for me:

  1. Generate Keys from the GIT GUI client on Windows. Copy this key to the clipboard.
  2. Open up your account on bitBucket/ git website, and add this key to your profile. This way, the server knows that you are a legitimate user accessing from a legitimate system.
  3. That's it. All push commands worked for me henceforth.