EC2 SSH 'Permission denied (publickey)' and Key File Errors
Workaround available Linux, macOS, Windows Updated November 13, 2026Based on 4 user reportsHow we research
Quick answer
Use the AMI's default username (ec2-user, ubuntu, admin...) with the exact key pair chosen at launch, and run chmod 400 on the .pem file.
Most likely fix: Use the right username
How to fix it
Try these in order — the most common fix is first.
1. Use the right username
- Amazon Linux: ec2-user; Ubuntu: ubuntu; Debian: admin; RHEL: ec2-user or root; Rocky: rocky; Bitnami: bitnami
- ssh -i key.pem ec2-user@<public-dns>
Did this fix it?2. Confirm the key pair
- EC2 > Instances > Details tab > Key pair name
- Use the matching .pem file
Did this fix it?3. Fix key file permissions
- macOS/Linux: chmod 0400 key.pem
- Windows: remove inherited permissions and grant yourself Read, or run icacls with /inheritance:r then /GRANT:R
Did this fix it?4. Debug with verbose output
- ssh -vvv -i key.pem user@host
- With PuTTY, convert .pem to .ppk using PuTTYgen (Load, then Save private key)
Did this fix it?5. Lost the key
- For EBS-backed instances: stop it, detach the root volume, attach it to a temporary instance, add a new public key to authorized_keys, reattach as the original device name and start
- Instance-store root volumes can't be recovered this way
Did this fix it?
Symptoms
ssh says Permission denied (publickey), 'UNPROTECTED PRIVATE KEY FILE', 'Server refused our key' or 'unable to load key'.
Why it happens
- Wrong username for the AMI
- Wrong or different key pair
- Key file permissions too open
- Key in OpenSSH format where PEM or PuTTY .ppk is needed
- Permissions of ~/.ssh or authorized_keys changed on the instance
- Lost the private key
This guide also covers
- permission denied publickey ec2
- ec2 unprotected private key file
- aws ssh server refused our key
- ec2 ssh key pair lost
Still not working?
If AWS keeps failing, you're not alone. See every AWS 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 usThe same problem in other apps
Other AWS errors
- AWS Unexpected Charges: Why Is My AWS Bill So High?
- AWS Charges After Free Tier: Why Am I Being Billed?
- AWS Account Suspended: How to Reactivate It
- EC2 SSH Connection Timed Out
- S3 Access Denied (403 Forbidden) Error
- AWS 'Not Authorized to Perform' IAM Error
- Lambda 'Task timed out after 3.00 seconds' Error
- CloudFront 403 Error: The Request Could Not Be Satisfied