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.
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
codeSyntaxError: Cannot use import statement outside a modulecodeTypeError: Cannot read properties of undefined (reading 'map')codedocker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?codegit push: error: failed to push some refs (rejected, non-fast-forward)codefatal: refusing to merge unrelated histories