Friday, 8 March 2019

Permission denied(publickey), fatal:couldn't read from remote repository - Gihub Error

     In the current post, we will check one of the gihub error while accessing the private repository code. I faced this issue recently when I try to access(git clone) private repository without adding ssh key into git-hub account.

The error message is,

C://WS/repo> git clone "URL Of PrivateRepo"

Permission denied (publickey).
fatal: Could not read from remote repository.

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

This means that GitHub is not able to authenticate you. There are two reasons,

1) You might not set up with a SSH key .  OR
2) Your generated SSH key is not associated with GitHub account.

First, we need to create SSH key to access the private Repository.

Create new SSH Key:-

 Open terminal of any directory, and type below command.  

$ ssh-keygen -t rsa -b 4096 -C "type your email here"

After enter the above command, then need to enter file name  to save the ssh key, by default it should save in the home directory of ssh folder.

Generating public/private rsa key pair.
Enter file in which to save the key (/home/administrator/.ssh/id_rsa):

Then enter the passphrase, or leave as it is just enter,

Enter passphrase (empty for no passphrase): [Type a passphrase]

After running all above commands, the SSH key will generate and it will save mentioned directory.

dir/id_rsa  , dir/id_rsa.pub

Copy the contents from id_rsa.pub file, and key should start with ssh-rsa,
and you can add into github account.


Add generated SSH key to GitHub account:--

Login to your GitHub account using basic credentials, i.e username/email and password.

Then go to Setting -> SSH and GPG keys 

SSH key generation


Click on New SSH Key,

Add SSH Key into Github account

Give key title, then add the generated key in the text box, key should start with ssh-rsa or ssh-dss or above mentioned text.
click on Add SSH key. It will add into the GitHub account.

Enable the key as follows,

Enable SSH Key

If you follow above steps properly, then you can able to access the code of private Repository.

Any doubt or clarifications, please put comment in the comment section.

Thank you......