Sometimes when you are trying to connect to an EC2 instance using SSH, you might get “UNPROTECTED PRIVATE KEY FILE!” Error. Your private key file must be protected from read and write operations from any other users. If your private key can be read or written to by anyone but you, then SSH ignores your key and you see this error. To mitigate the issue simply change the permission level to your SSH private key file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
## --------------- ## Linux or MAC OS ## --------------- ## check the permission of your private key ls -l ~/.ssh/ ## change the permission of your private key chmod 0400 ~/.ssh/ ## You should be able to connect to your Linux instance from Linux or Mac via SSH. ## ---------- ## Windows OS ## ---------- ## From the command prompt, navigate to the file path location of your .pem file. ## Run the following command to reset and remove explicit permissions icacls.exe $path /reset ## Run the following command to grant Read permissions to the current user icacls.exe $path /GRANT:R "$($env:USERNAME):(R)" ## Run the following command to disable inheritance and remove inherited permissions. icacls.exe $path /inheritance:r ## You should be able to connect to your Linux instance from Windows via SSH. |