publickey 🌿 Git

Git: Permission denied (publickey). fatal: Could not read from remote repository.

SSH authentication to GitHub/GitLab/Bitbucket failed — no key, wrong key, or the key isn’t added to your account.

Seen on: Git Linux

Meaning

The remote uses SSH (git@github.com:…) and the server didn’t accept any key your SSH client offered.

Common causes

  • No SSH key generated
  • Public key not added to the Git host account
  • ssh-agent not running/key not loaded
  • Wrong key used (multiple accounts)
  • Corporate network blocks port 22

⚡ Quick fix

  1. Test: ssh -T git@github.com
  2. Generate a key: ssh-keygen -t ed25519 -C "you@example.com"
  3. Add ~/.ssh/id_ed25519.pub to your Git host account
  4. ssh-add ~/.ssh/id_ed25519
  5. Or switch the remote to HTTPS with a token

Detailed fix by platform

Git

  1. Debug which key is offered:
    bash
    ssh -vT git@github.com
    # Port 22 blocked? Use SSH over 443:
    # ~/.ssh/config
    Host github.com
      Hostname ssh.github.com
      Port 443
      User git

How to diagnose

  1. Remote — SSH or HTTPS URL?
  2. Key — Which key does ssh -v offer?
  3. Account — Is that key added?
  4. Network — Port 22 reachable?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.