I'm trying to SSH connect to an EC2 instance inside of VSCode, but I keep getting this error:
https://i.stack.imgur.com/SAhf1.jpg
It says my pem file is "too open" and "not protected" so it's denying access.
My issue is I already used this pem file as a key to a different instance and it worked fine. I already ran "chmod 400 swayek.pem" a few days ago and it worked.
I tried running it again multiple times:
https://i.stack.imgur.com/PovQq.jpg
but I'm still not able to connect.
BUT it works and connects when not using VScode. This actually connects fine:
ssh -i swayek.pem ec2-user@ec2-44-212-10-54.compute-1.amazonaws.com
https://i.stack.imgur.com/FDbqU.png
I think WSL2 is causing the problem because my SSH key is in the WSL2 distro side and VSCode isn't connected to the WSL distro when running SSH.
Normally I'm connected to Ubuntu like this:
https://i.stack.imgur.com/E7Rpi.png
but it doesn't allow you to open SSH from inside a Ubuntu container. It always opens a new window and connects to SSH from the default windows terminal. I'm not 100% sure but I think that's the problem.
Does anybody with more knowledge know what the issue is here and how to fix it?
EDIT:
I figured I would just try to copy the "swayek.pem" file over to the windows side and set the permissions on that.
I followed this [Github post][1] as the Windows equivalent to "chmod 400":
# Source: https://stackoverflow.com/a/43317244
$path = ".\aws-ec2-key.pem"
# Reset to remove explict permissions
icacls.exe $path /reset
# Give current user explicit read-permission
icacls.exe $path /GRANT:R "$($env:USERNAME):(R)"
# Disable inheritance and remove inherited permissions
icacls.exe $path /inheritance:r
https://i.stack.imgur.com/euPFR.jpg
But now I'm getting a DIFFERENT error and I dont understand it. Can anyone decipher this error?