Codespaces "Permission denied (publickey)" and Git Push/Clone Failures

Share
Workaround available Browser, VS Code Updated November 14, 2026How we research

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. 1. Fix SSH rewrite

    1. Remove the SSH rewrite from dotfiles
    2. Or apply it only when the CODESPACES environment variable is empty
    Did this fix it?
  2. 2. Access other repositories

    1. Preferred: declare extra permissions in devcontainer.json (new codespaces only)
    2. Or create a fine-grained personal access token with Contents permission limited to needed repos
    3. 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 us
Fixed it? Share this guide

The same problem in other apps

All storage, upload & download guides →

Other GitHub Codespaces errors

All 11 GitHub Codespaces errors and fixes →