How to Fix Warning: Unprotected Private Key File!

This article provides a fix to “warning: unprotected private key file!” on Linux and Windows OS. So, you want to be surreal to follow the article to the end to learn the simple command to fix on your Linux and steps to take on Windows to fix this as well.

However, before we deal with the “unprotected private key file!” let’s quickly take a look at what and why you keep seeing this error message.Warning: Unprotected Private Key File!

Username and Password Vs Server

When you want to connect to a server you’d need to either use a password and username or private keys. Although both methods can be used but using private keys can be more confusing as a single mistake can lead to unexpected errors because you need to run SSH with extra commands. But with the use of a password and username, the process can be pretty straightforward and direct.

Why You Keep Seeing “Warning: Unprotected Private Key File!

The warning: unprotected private key file! error occurs when you try to sign in to an SSH server with an unsecured or opened permission. However, in most cases, you’d need to change the permission to fix the unprotected private key file.

Another reason why you’d experience this error is that someone else has altered or changed the hidden .ssh folder in the users’ directory.

Change SSH Private Key Permission

If your SSH private key permission is set to public, then, you need to change the key permission.

  • Locate the SSH Private key location on your Linux.
  • Launch “Terminal.”
  • You can get the private key permission that brought about the error [this is optional though].
  • Change the private key level to the level that is acceptable that won’t return the “warning: unprotected private key file!.”
$ chmod 600 .ssh/simplified-guide.pem
  • Now, try the SSH private key authentication whether it’ll return the error message again.

How to Fix “Warning: Unprotected Private Key File!”

You’d not want a random fellow to help you fix this as it might cause more problems than expected. So, we will consider how to fix this aws warning error message on Linux and Windows.

Reset the Private Key Permission

You can also reset the Linux private key file to the default permission.

udo chmod 600 ~/.ssh/id_rsa
sudo chmod 600 ~/.ssh/id_rsa.pub

This should work. However, if it’s not working and you are getting another error; just try the following again.

Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/geek/.ssh/known_hosts).

If it fails to add the host to the list of known hosts it means that the file was set incorrectly. With this, you need to adjust it with the command below.

sudo chmod 644 ~/.ssh/known_hosts

Once you have adjusted the file with the command above you then need to adjust the directory permission with the command below.

sudo chmod 755 ~/.ssh

How to Fix Warning: Unprotected Private Key File! on Windows

Follow the steps below if you are connecting Windows!

  • Go to the .pem file.
  • Right-click on the file and scroll down to select “properties.”
  • Go to the “Advanced” tab and select “Advanced.”
  • Confirm that you have the administrative right else the owner’s username will have to be changed.
  • Choose “Disable Inheritance” and “Remove all inherited permission from this subject.”
  • Select “Add” >> “Select a principal” >> “Enter username” >> OK.
  • Enable “Read Permission” >> Ok [in the permission entry window].
  • Select “OK” >> “OK.”
  • Select the “Advanced Security Settings >> Properties.”

Now, you will be able to connect the Linux instance from your Windows via SSH.

With these steps in this guide, you should be able to handle and fix the “warning: unprotected private key file!” error message on your Linux and Windows via SSH.

Leave a Comment