Codespaces "Permission denied (publickey)" and Git Push/Clone Failures
Quick answer
Codespaces authenticates Git over HTTPS with GITHUB_TOKEN. Remove SSH rewrites from your dotfiles, and use a fine-grained token for other repositories.
Most likely fix: Fix SSH rewrite
How to fix it
Try these in order — the most common fix is first.
1. Fix SSH rewrite
- Remove the SSH rewrite from dotfiles
- Or apply it only when the CODESPACES environment variable is empty
Did this fix it?2. Access other repositories
- Preferred: declare extra permissions in devcontainer.json (new codespaces only)
- Or create a fine-grained personal access token with Contents permission limited to needed repos
- Add it as a secret named GH_TOKEN and reload; clone with gh repo clone
Did this fix it?
Symptoms
"git@github.com: Permission denied (publickey)", "Host key verification failed", or you cannot clone or push to another repository.
Why it happens
- Dotfiles set a url.insteadOf rewrite to SSH
- GITHUB_TOKEN only covers the repository the codespace was created from
This guide also covers
- codespaces permission denied publickey
- codespaces git push failed
- codespaces host key verification failed
Still not working?
If GitHub Codespaces keeps failing, you're not alone. See every GitHub Codespaces problem users report or the alternatives people switch to.
Have an app idea? Our small team builds any software: web and mobile apps, games, desktop, AI tools. Price agreed together.
Talk to usThe same problem in other apps
Other GitHub Codespaces errors
- Codespace Running in Recovery Mode: "This codespace is currently running in recovery mode due to a container error"
- GitHub Codespaces Creation Failed
- Can't Create a Codespace: No Option to Create on the Repository
- GitHub Codespaces "503 Service Unavailable" Error
- Codespaces "Oh no, it looks like you are offline" and Other Connection Errors
- GitHub Codespaces Port Forwarding Not Working
- Codespace Out of Storage: How to Free Disk Space
- Codespaces Included Usage Used Up: Core Hours and Storage Quota