How to fix “Unprotected Private Key File!”-errors when trying to connect to a EC2 machine

Most Amazon EC2-users run in the to pesky “Permissions XXXX for ‘xxx.pem’ are too open. It is required that your private key files are NOT accessible by others.”-problem from time to time. And the solution is surprisingly simple.

Since you are trying to access a machine using a private key, SSH requires that this key is only readable by the current user. This is to ensure that no-one else on the system can access this file and use it.

Simply change the permission of the .pem file to 400, which means that it’s only accessible by your user and the problem will be fixed:

chmod 400 xxx.pem