What the message looks like
fatal: Could not read from remote repository.Common causes
- The SSH key is not loaded (no agent) or not registered in the Git host account.
- The remote URL is wrong, or the repository was renamed, moved or deleted.
- The account has no access to the repository, or it is private and the wrong user is signed in.
- A different key is offered than expected, for example because several keys are in the agent.
- Network problem: the host is unreachable, the host key changed or port 22 is blocked.
Check
- Which remote URL is set?
git remote -v - Test the SSH login to the Git host
ssh -T git@github.com - Verbose SSH output: which keys are offered?
ssh -vT git@github.com 2>&1 | grep -iE 'offering|denied|authenticated' - Which keys does the agent hold?
ssh-add -l
Fix
- Read the line above the error: "Permission denied (publickey)" points to key problems, "Could not resolve hostname" to DNS or a typo, "Repository not found" to a name or permissions issue.
- Load the key:
ssh-add ~/.ssh/id_ed25519, and add the public key to the host account. - With several keys, set
IdentityFileandIdentitiesOnly yesper host in~/.ssh/config. - Correct the remote URL:
git remote set-url origin git@github.com:user/repo.git. - Alternatively switch to HTTPS with an access token if SSH is not possible on the network.
Typical scenario
On a freshly set up laptop git clone git@github.com:company/project.git fails with Permission denied (publickey) and the fatal message. The key exists in ~/.ssh but was never added to the GitHub account. After pasting the output of cat ~/.ssh/id_ed25519.pub into the SSH settings, ssh -T git@github.com reports a successful login and the clone goes through.
FAQ
Does the message always mean the repository does not exist?
No. "Please make sure you have the correct access rights and the repository exists" is a generic hint. For private repos some hosts deliberately report missing access as a non-existent repository.
How do I test the connection without changing the repo?
Use git ls-remote origin. It only reads the references and performs the same authentication as fetch and push.
What does "Host key verification failed" before it mean?
The host key was never confirmed or has changed. Check the fingerprint with the provider and, for a genuine change, remove the old entry with ssh-keygen -R github.com.
Why does it work in the terminal but not in my IDE?
IDEs and cron jobs often have no access to the SSH agent of the login session. Either pin the key in ~/.ssh/config or set SSH_AUTH_SOCK for the process.
Do I need to type a password when Git asks for one?
With SSH the prompt is for the key's passphrase, not the account password. ssh-add stores it once per session in the agent. For HTTPS, hosts no longer accept the account password; a token is required.