SSH Permission Denied (publickey) Error
Fix 'Permission denied (publickey)' SSH errors when connecting to GitHub, AWS, or remote servers.
What Does This Error Mean?
The 'Permission denied (publickey)' error means the SSH server rejected your connection because your public key is not recognized or the corresponding private key is not available to the SSH client.
Common Causes
SSH key has not been added to the remote server's authorized_keys
Wrong SSH key is being used (default key is not the right one)
Private key has incorrect permissions (too permissive)
ssh-agent is not running or the key is not added to it
Connecting with the wrong username
SSH key was removed from the server (e.g., GitHub deploy key removed)
How to Fix It
Check key permissions
SSH private keys must have strict permissions to be accepted.
# Fix private key permissions (Linux/macOS) chmod 600 ~/.ssh/id_rsa chmod 700 ~/.ssh chmod 644 ~/.ssh/id_rsa.pub # On Windows, check Properties → Security → Advanced # The key should be readable only by the user
Add key to ssh-agent
Register your SSH key with the SSH agent.
# Start ssh-agent ssh-agent bash # or eval "$(ssh-agent -s)" # Add your key ssh-add ~/.ssh/id_rsa # List added keys ssh-add -l # Test connection ssh -T git@github.com
Add public key to the remote server
Copy your public key to the server's authorized_keys.
# Copy public key to server ssh-copy-id user@server.com # Or manually append to ~/.ssh/authorized_keys cat ~/.ssh/id_rsa.pub | ssh user@server.com "cat >> ~/.ssh/authorized_keys" # For GitHub: add key at https://github.com/settings/keys # Test: ssh -T git@github.com # Should say: "Hi username! You've successfully authenticated"
Specify which key to use
Use -i flag to specify a specific private key.
# Connect with specific key ssh -i ~/.ssh/my-custom-key user@server.com # Or configure in ~/.ssh/config Host myserver HostName server.com User ubuntu IdentityFile ~/.ssh/my-custom-key
Related Tools
Use these tools to debug and fix this error:
Related Errors
Other common errors in this category:
401 Unauthorized Error
Learn what a 401 Unauthorized error means, common causes, and how to fix authentication failures in your web applications.
403 Forbidden Error
Learn what 403 Forbidden means, how it differs from 401, and how to fix access denied errors in your applications.
404 Not Found Error
Learn what 404 Not Found means, common causes, and how to fix broken links and missing resources on your website or API.
429 Too Many Requests Error
Learn what 429 Too Many Requests means, how rate limiting works, and how to handle or avoid hitting API rate limits.