# Git "git@github.com: Permission denied (publickey)" - Deploy Key in CI

> Fix Git SSH "git@github.com: Permission denied (publickey)" in CI for deploy keys - the right private key is not offered, or the deploy key is added to the wrong repo or read-only.

Source: https://latchkey.dev/learn/git/git-publickey-permission-denied-deploy-key  
Updated: 2026-06-25

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.

## Diagnose it: depth, refs, or credentials?

```Terminal
git rev-parse --is-shallow-repository
git rev-parse --abbrev-ref HEAD    # prints HEAD when detached
git log --oneline -3
git remote -v
```

> `actions/checkout` fetches depth 1 on a detached HEAD. Anything diffing against a base, reading a branch name, or running `git describe` needs `fetch-depth: 0`.

## FAQ

### What causes Git "git@github.com: permission denied (publickey)"?

There are 3 common causes: the deploy key is on the wrong repo, the wrong key is offered, and a read-only deploy key used for a push. A deploy key is repo-specific.

### How do I fix Git "git@github.com: permission denied (publickey)"?

There are 2 fixes depending on which cause you have: pin the exact key per host and verify the deploy key and its access. Work through them in order, since the first is the most common.

### What does Git "git@github.com: permission denied (publickey)" actually mean?

An SSH clone/push fails with git@github.com: Permission denied (publickey) and fatal: Could not read from remote repository.

### How do I stop Git "git@github.com: permission denied (publickey)" happening again?

Add a dedicated deploy key per repo and pin it with IdentitiesOnly yes. The prevention section lists 3 changes that keep it from recurring.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
