1

I have been trying to run these commands but I keep getting permission denied

I tried this chmod 400 xxxxxx.pem and with sudo too.

The current permissions are -r--r--r-- for the pemfile. Please help. I cannot connect to my EC2 instances without this pem file.

IF i try to connect i get this error

Warning: Permanently added 'ec2-x54-xxx-xxx-xxx.compute-1.amazonaws.com' (ECDSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0444 for 'xxxxxx.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "xxxxxx.pem": bad permissions

I have tried this on WSL2-ubuntu and git bash.

1
  • Is the file located in a directory that you don't own? Create a new dir, move it there and try again with chmod.
    – chamal
    Commented Jan 4, 2023 at 6:51

1 Answer 1

4

If you're referencing files in the Windows file system, they do not, by default, retain Linux permissions. However, there's a way to enable that. Edit or create (using sudo) /etc/wsl.conf and add the following:

[automount]
options = "metadata"

Close all WSL terminals and open a new one.

Note: If the private key is on your Windows filesystem (under /mnt/), You can't modify the permissions of files on Windows's filesystem using chmod on Bash on Ubuntu on Windows. You'll have to copy the private key to your WSL home directory (~) and do it there.

2
  • 2
    Thank you. this worked. I moved the file to WSL home directory and i was able to change permissions.
    – ClickOps
    Commented Jan 12, 2023 at 3:44
  • 1
    You are a saver!!! This took me a lot of time to figure out while going crazy.
    – ViKeR81
    Commented Mar 21 at 16:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.