Stepwise
Verified by debateUpdated Jul 22, 2026

technology · v1

Fixing GitHub Permission Denied Publickey Errors

This guide helps you troubleshoot and resolve SSH authentication failures when pushing to GitHub. You will verify your keys, generate new credentials, and configure your SSH agent.

Verify the SSH Connection

Open your terminal and run the connection test command to confirm if GitHub rejects your current key 1. If you receive a permission denied error, proceed to the next step 14.

Test connection
ssh -T git@github.com

Check for Existing SSH Keys

List the contents of your hidden .ssh directory to see if you already have an existing key pair 2. Look for files named id_ed25519.pub or id_rsa.pub 4.

List keys
ls -al ~/.ssh

Generate a New SSH Key

If no key exists, generate a new Ed25519 key, which is the current security standard 4. Press Enter to accept the default file location and skip the passphrase if preferred 11.

Generate key
ssh-keygen -t ed25519 -C "your_email@example.com"

Advertisement

Add Key to SSH Agent

Start the SSH agent in the background and add your new private key to ensure your system uses it for authentication 12. Never use sudo with these commands to avoid ownership conflicts 16.

Add to agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Upload Public Key to GitHub

Display your public key and copy the entire output 2. Navigate to your GitHub account settings, select SSH and GPG keys, and add a new SSH key 11. Ensure you only upload the file ending in .pub 4.

Show public key
cat ~/.ssh/id_ed25519.pub

Troubleshoot Persistent Errors

If the error persists, run the verbose connection command to identify if the system is attempting to use the wrong key or encountering file permission issues 14.

Verbose test
ssh -vT git@github.com

Sources

Every step cites the sources below. Facts are rechecked automatically every 90 days or whenever a reader flags an error.

  1. oneuptime.com
  2. github.com
  3. medium.com
  4. github.com
  5. youtube.com
  6. youtube.com
  7. youtube.com
  8. askubuntu.com
  9. youtube.com
  10. youtube.com
  11. github.com
  12. github.com
  13. youtube.com
  14. oneuptime.com
  15. medium.com
  16. stackoverflow.com
  17. dev.to
  18. geeksforgeeks.org
  19. goteleport.com
  20. medium.com

Advertisement

Guides are written entirely by AI, with no human author. May be wrong. Not professional advice; use at your own risk. Terms · Privacy