The warning "WARNING: UNPROTECTED PRIVATE KEY FILE!" typically occurs when the permissions on the private key file used for SSH authentication are set too permissive. SSH is designed to protect the private key file because it grants access to the server. If the permissions are too relaxed, SSH may refuse to use the key file for security reasons.
To resolve this issue, you need to adjust the permissions of the private key file. Here are the recommended steps:
Locate the private key file on your local machine. It usually has a .pem extension.
Open a terminal or command prompt.
Set the permissions of the private key file to be more secure by running the following commands:
chmod 400: By setting the permissions to 400 (readable by the owner only), you ensure that the private key file is adequately protected
chmod 400 /path/to/private_key.pem
Replace /path/to/private_key.pem with the actual path to your private key file.
chmod 700: Setting the permissions to "chmod 700" for the private key file is also a valid approach, and it restricts access to the file only for the owner.
This means that the owner has read, write, and execute permissions, while all other users have no access to the file.
chmod 700 <path/to/private_key_file>
Replace <path/to/private_key_file> with the actual path to your private key file.
After adjusting the permissions, try SSHing into your EC2 instance again using the private key file:
ssh -i /path/to/private_key.pem user@ec2-instance-ip
Replace /path/to/private_key.pem with the correct path to your private key file, user with the appropriate username for your EC2 instance, and ec2-instance-ip with the public IP address or hostname of your EC2 instance.
You should be able to SSH into your Amazon EC2 instance without encountering the "WARNING: UNPROTECTED PRIVATE KEY FILE!" message.