wesupport

Need help?

Our experts have had an average response time of 13.14 minutes in February 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

EC2 error: unprotected private key file | Resolved

by | Dec 5, 2021

EC2 error: unprotected private key file causing trouble?

At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Service.

Let’s take a look at how our Support Team recently helped a customer by resolving EC2 error: unprotected private key file.

How to resolve EC2 error: unprotected private key file

If the private key is left unprotected, it can be read or written by anyone. Furthermore, it causes SSH to ignore the key and send a warning message as seen below:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
Permissions 0777 for '.ssh/my_private_key.pem' are too open. It is required that your private key files are NOT accessible by others. This private key will be 
ignored. bad permissions: ignore key: .ssh/my_private_key.pem Permission denied (publickey).

In case you come across a similar message while attempting to log into the instance, ensure that you are using the correct public key. Our Support Tech recommends fixing this error with the following command for MacOS or Linux:

[ec2-user ~]$ chmod 0400 .ssh/my_private_key.pem

Remember to substitute the path with the private key file.

How to resolve EC2 error: unprotected private key file in Windows

If we are connecting from Windows, we have to follow these steps:

  1. First, we will navigate to the .pem file.
  2. Then, we have to right-click on the file and choose Properties.

  3. Next, we will select Advanced under the Advanced tab.
  4. After that, we have to verify that we are the owner of the file. If not, we will change the owner to our username.
  5. Then, we have to select Disable inheritance as well as Remove all inherited permissions from this object.

  6. Next, we will select Add followed by Select a principal and enter our username and click OK.
  7. After that, we will grant Read permissions and click OK in the Permission Entry window.
  8. Then, we have to select OK twice to close the Advanced Security Settings and Properties windows.
  9. Finally, we will be able to connect the Linux instance from Windows through SSH.

We can accomplish the same from a command prompt in Windows with these steps:

  1. First, navigate to the file path location of the .pem file.
  2. Next, reset and remove explicit permissions with this command:
    icacls.exe $path /reset
  3. Then, grant Read permissions to the current user via this command:
    icacls.exe $path GRANT:R "$($env:USERNAME):(R)"
  4. After that, we have to disable inheritance as well as remove inherited permissions with the following command:
    icacls.exe $path inheritance:r
  5. Now, we will be able to connect to the Linux instance via SSH from Windows.

[Stuck with a different query? We are available 24/7.]

Conclusion

In brief, the skilled Support Engineers at Bobcares demonstrated how to resolve the unprotected private key file error with ease.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

 

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Categories

Tags