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.
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.
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.
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.
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.
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.
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.
Advertisement