EC2 SSH 'Permission denied (publickey)' and Key File Errors

Share
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. 1. Use the right username

    1. Amazon Linux: ec2-user; Ubuntu: ubuntu; Debian: admin; RHEL: ec2-user or root; Rocky: rocky; Bitnami: bitnami
    2. ssh -i key.pem ec2-user@<public-dns>
    Did this fix it?
  2. 2. Confirm the key pair

    1. EC2 > Instances > Details tab > Key pair name
    2. Use the matching .pem file
    Did this fix it?
  3. 3. Fix key file permissions

    1. macOS/Linux: chmod 0400 key.pem
    2. Windows: remove inherited permissions and grant yourself Read, or run icacls with /inheritance:r then /GRANT:R
    Did this fix it?
  4. 4. Debug with verbose output

    1. ssh -vvv -i key.pem user@host
    2. With PuTTY, convert .pem to .ppk using PuTTYgen (Load, then Save private key)
    Did this fix it?
  5. 5. Lost the key

    1. 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
    2. 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 us
Fixed it? Share this guide

The same problem in other apps

All not loading, error messages & connection guides →

Other AWS errors

All 11 AWS errors and fixes →