Resolve git issue git@github.com: Permission denied (publickey)

  sonic0002        2019-07-12 10:10:49       18,461        0    

Sometimes when clone a remote repository from github.com, you may see below error.

D:\Project\Playground\GitBisect>git clone git@github.com:bradleyboy/bisectercise.git
Cloning into 'bisectercise'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

The issue occurs when there is no key on your machine which is associated with your github account. To fix the issue, please go to ~/.ssh and check whether you have correct private and public key generated and stored and associate them with your github account.

If there is no key in .ssh folder, you can run below command to generate the key pairs.

D:\Project\Playground\GitBisect>ssh-keygen -t rsa -b 2048 -C "github_email_account"
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\pike6/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\pike6/.ssh/id_rsa.
Your public key has been saved in C:\Users\pike6/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:mOCNcDb4Te+S+bCcKfreoH0Or7QMgRc1iXMFw2GwOeo github_email_account
The key's randomart image is:
+---[RSA 2048]----+
|  .+B=.          |
|  o*+o           |
|  Bo= .          |
| o O B +         |
|o o + = S        |
|.. .   +         |
| E. + = .        |
|   *.B.B         |
|  o+B=O .        |
+----[SHA256]-----+

You will see the RSA private and public are generated in .ssh folder.

Open id_rsa.pub and copy the content and add a new key in your github account profile setting.

Once the key is added, you can try to clone the repository again. And now you should be able to see the repository can be cloned successfully.

D:\Project\Playground\GitBisect>git clone git@github.com:bradleyboy/bisectercise.git
Cloning into 'bisectercise'...
remote: Enumerating objects: 304, done.
Receiving objects:  47% remote: Total 304 (delta 0), reused 0 (delta 0), pack-reused 304
Receiving objects: 100% (304/304), 29.88 KiB | 111.00 KiB/s, done.
Resolving deltas: 100% (97/97), done.

GITHUB  PERMISSION DENIED  GIT  PUBLIC KEY 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

A sad outsourcing story