In this article, you will find out the steps on how to fix the EC2 error “Warning: Unprotect Private Key File.” The reason that you see this error because your are trying to SSH in a AWS EC2 instance by using a private key which allow you to read access to other users.
Source: >BobbyHadz
To solve this warning error “Warning: Unprotected Private Key File” in AWS EC2, you need to update the private key file permission which only allow you read access from the current user, for instance, chmod 600 ec2-private-key.pem.
There are same approach whether you want to fix Warning Unprotect Private Key File in Windows 10 and Windows 11.
First and foremost, open the terminal in the directory in the location where your private key is and run the chmod command.
After running this command, try to SSH into the AWS EC2 instance again. The following is the command for Amazon Linux instances:
To fix the Warning Unprotect Private Key File in AWS EC2 there are different approaches. In case you’re still getting the error, try to change the directory permission containing the private key. For instance, you could store the keys in a ec2 directory, the following command will be used:
In the end, ensure that you use the correct ssh command. The username of the command varies in the different Amazon machine images (like ubuntu, or ec2-user).
Get the correct ssh command for the EC2 instance:
Navigate to the EC2 console and tap on the checkbox next to the nae of the instance.
Tap on the Actions and choose Connect.
Tap on the SSH client tab and copy ssh command example.
Source: >BobbyHadz
This is the easy way to search for your username for your AMI by logging in as root and read the error message.
Source: >BobbyHadz
The following is the SSH command you should look into: