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

ID : 20203

viewed : 32

Tags : gitgit-clonegit

Top 5 Answer for git clone - Git: Permission denied (publickey) fatal - Could not read from remote repository. while cloning Git repository

vote vote

96

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 git@github.com:%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.

vote vote

83

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.

vote vote

73

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

vote vote

60

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.
vote vote

57

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

Top 3 video Explaining git clone - Git: Permission denied (publickey) fatal - Could not read from remote repository. while cloning Git repository

Related QUESTION?