I was trying to use an ssh instance and I recieved this error:

Permissions 0777 for 'privkey.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 "privkey.pem": bad permissions
Permission denied (publickey).

Which is odd. I tried to change the permission using the 'chmod' command, but that didn't seem to work. The bash gave the impression that the command registered, but I checked the permissions of the key and it was still at 777. I opened my git bash and I was able to ssh into my instance with no problem, and the permissions were not 777 as well.

up vote 8 down vote accepted

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:

options = "metadata"

Shut down all WSL instances and restart an instance, and any chmod changes are now retained.

  • 3
    This is the absolute right answer! – kontinuity Aug 5 at 14:36

Is the private key 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.

Some discussion here: https://github.com/Microsoft/WSL/issues/81

  • 2
    There are at least 3 pages to that discussion. You really should quote the information you feel is relevant to the author. – Ramhound May 17 at 18:23
  • 1
    The thing was that perviously, I was able to ssh into my instance with no problem. This only started happening today – iii May 17 at 18:42
  • 1
    @iii So what changed recently? Did you install any windows updates? Did you change any config files? Please edit and update your question. – DavidPostill May 17 at 18:53
  • 1
    @iii - Which update? Your question makes no reference to the fact it was working previously. Your question also makes no reference that you recently installed an update. I disagree with this answer, because the link is from before WSL was modified (I believe), to support what you are trying to do. Which is the reason I was pressing the author to elaborate thier answer – Ramhound May 17 at 19:09
  • 2
    @Ramhound, the relevant information from that discussion is paraphrased in my answer, I just added that link as a reference source. The relevant information is in the first reply there. I didn't know that the questioner only encountered this problem after a Windows update, but they haven't said whether the key is on the Windows filesystem, so I still think that's the most likely explanation until they indicate otherwise. – erobertc May 17 at 21:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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