SSH Permissions Issue for EC2 AWS Key pair

Ran into an issue where I created a new AWS instance, configured a new key pair so I can SSH into my test machine and received the following error message when connecting to it (names and addresses generic of course):

mycomputer$ ssh user@ -i myprivatekey.pem
Permissions 0644 for ‘myprivatekey.pem’ are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key “myprivatekey.pem”: bad permissions
user@ Permission denied (publickey).

What this is telling you is that the unix permissions for the .pem file are too loose and need to be locked down. The file that you pulled down from AWS when you created the key has unix permissions of 644 (by default) which are [-rw-r–r-] and need to be changed to 400 or [-r——–]. So here is the command you need to run on your .pem file:

mycomputer$ chmod 400 myprivatekey.pem

Issue the same command listed above and you should be able to connect.

*Of course, for best security practice – I recommend that you lock down what IP(s) can connect to your instances for SSH.