Skip to content
Latchkey

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 clone output
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.

Terminal
cat >> ~/.ssh/config <<'EOF'
Host github.com
  IdentityFile ~/.ssh/deploy_key
  IdentitiesOnly yes
EOF
ssh -T git@github.com

Verify the deploy key and its access

  1. Confirm the public key is added as a deploy key on this exact repository.
  2. For pushes, enable "Allow write access" on the deploy key.
  3. Use ssh -vT git@github.com to 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’s ssh-key input, which wires the key correctly.

Frequently asked questions

What causes ""Permission denied (publickey)""?
A deploy key is repo-specific. A key added to repo A cannot authenticate to repo B, so the server denies it.
How do I fix "Permission denied (publickey)"?
Configure SSH to use only the intended key for the host so the deploy key is offered first.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card