Sat Sep 25 2021·2 min read
Photo by Philipp Kämmerer
The reason the "Warning: Unprotected Private Key File" AWS error occurs is because we're trying to SSH into an EC2 instance using a private key that allows read access to other users.
A private key must only be readable by your user on the machine in order to allow you to SSH into an EC2 instance.
In order to solve the "Warning: Unprotected Private Key File" error in AWS EC2, update the permissions of the private key file to only allow read access from the current user.
Open your terminal in the directory where your private key is located and run
chmod 600 ec2-private-key.pem
Try to ssh into the EC2 instance again, for amazon linux instances the command looks like:
ssh -i "ec2-private-key.pem" ec2-user@YOUR_EC2_PUBLIC_DNS
If you are still getting the error try changing the permissions of the directory
that contains the private key. For example if you store your keys in a directory
ec2, you would do:
chmod 755 ./ec2
ec2-private-key.pemfile is stored, otherwise you might get a permissions denied error because the file could not be found.
Lastly, make sure you're using the correct ssh command, the username varies
between the different amazon machine images (e.g.
To get the correct ssh command for your EC2 instance:
SSH clientTab and copy the example ssh command