Monday, December 20, 2021

GIT: Error: Permission denied (publickey)

Related issues are:
$ git clone https://github.com/somecderepo
Cloning into 'somecderepo'...
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.
And:
$ ssh-add ~/.ssh/id_rsa.pub 
Could not open a connection to your authentication agent. 

There are many answers for this across the net, preferred article on the GIT website for this error,
but after following it so many times my issue was not getting resolved, in short the steps on GIT say (commands for Git bash only):

1. make sure you have git Agent running by typing exec ssh-agent bash, if not run it by typing, 

$ eval "$(ssh-agent -s)"

2. Once the git agent is running copy the SSH key contents from your git .ssh folder, 

 pbcopy < keyname.pub

3. if the .ssh key is not present generate one and then copy

$ ssh-keygen -t ed25519 -C "gitusername/email@email.com"

  4. associate the key with the agent,

$ ssh-add -l -E sha256

5. associate same key with your online git account, In the user settings sidebar, click SSH and GPG keys

While following these steps if you encounter the problem that the key cannot be read or it is not getting created, it may be down to the administrative permission of your machine, following was the case with my machine:

Turned out the problem was that the default ssh directory (normally C:\Users\username\.ssh) was not open to read the for ssh key to the Git Bash, so I was getting following error:

To resolve this you have to change the directory from default Git Bash directory to any accessible location (cd /location) and generate the key again, then copy the kay.pub and key file and paste it to the .ssh folder





No comments: