Permission denied (publickey). fatal: Could not read from remote repository.
TL;DRThis error happens when Git cannot connect to a remote code repository because the computer lacks the correct SSH key permission.
Most likely cause: SSH key not added to the remote account or agent
Try first: Check current SSH keys (ls -la ~/.ssh)
Likely causes
- SSH key not added to the remote account or agentmost likely
- Wrong remote URL or key file permissionspossible
- Key file missing or not generatedless likely
How to fix it
Safest first: SafeChanges settingsDangerous
Check current SSH keysSafe
List the SSH keys present on the system to see if any exist.
ls -la ~/.sshTest connection to the remoteSafe
Run a simple SSH test to confirm the permission issue.
ssh -T git@your-remote-hostAdd key to SSH agentChanges settings
Start the agent and load the key so Git can use it.
ssh-add ~/.ssh/id_rsa
If that didn't fix it
You will continue to be unable to push or pull changes from the remote repository.
When to see a technician
Consult a technician if you are unsure which key belongs to the repository or if the remote account access needs to be reset.
Related errors
codefatal: unable to access 'https://github.com/example/repo.git/': Could not resolve host: github.comcodefatal: not a git repository (or any of the parent directories): .gitcodepermission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sockcodenpm ERR! code EACCES: permission denied, mkdir '/usr/local/lib/node_modules'codefatal: Authentication failed for 'https://github.com/user/repo.git/'codefatal: refusing to merge unrelated histories