Git "git@github.com: Permission denied (publickey)" - Deploy Key in CI
SSH offered a key the server would not accept. With deploy keys the usual issue is that the specific key for this repo is not the one being offered, or the deploy key is on the wrong repo or lacks write access for a push.
What this error means
An SSH clone/push fails with git@github.com: Permission denied (publickey) and fatal: Could not read from remote repository. A different repo using its own deploy key works, which points at the key/repo pairing.
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.Common causes
The deploy key is on the wrong repo
A deploy key is repo-specific. A key added to repo A cannot authenticate to repo B, so the server denies it.
The wrong key is offered
With several keys in the agent, SSH may offer a different identity first and never reach the deploy key, especially without IdentitiesOnly.
A read-only deploy key used for a push
A deploy key without write access authenticates for clone but is denied on push.
How to fix it
Pin the exact key per host
Configure SSH to use only the intended key for the host so the deploy key is offered first.
cat >> ~/.ssh/config <<'EOF'
Host github.com
IdentityFile ~/.ssh/deploy_key
IdentitiesOnly yes
EOF
ssh -T git@github.comVerify the deploy key and its access
- Confirm the public key is added as a deploy key on this exact repository.
- For pushes, enable "Allow write access" on the deploy key.
- Use
ssh -vT git@github.comto see which key is offered and accepted.
How to prevent it
- Add a dedicated deploy key per repo and pin it with
IdentitiesOnly yes. - Grant write access to deploy keys that must push.
- Prefer
actions/checkout’sssh-keyinput, which wires the key correctly.