6

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

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
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.

17

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"

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 '18 at 14:36
  • 1
    Does not work for me. I did exactly as you suggest, but permission set using chmod still do not reflect when doing a ls -al. Strangely enough (and this was also the case prior to doing this change), certain chmod values work while others don't. For e.g, 0600 has no effect but 0400 changes it to -r-xr-xr-x. – Ash Jan 28 at 6:19
  • @Ash make sure your WSL permissions doesn't contradict the Windows permission. E.g. if you mark a file read-only in Windows, it won't be writable in WSL either, as the Windows permissions overrules the WSL permissions. – nilskp Jan 28 at 16:10
  • @nilskp The file is not marked Readonly under Windows and the Windows permissions for it are Full Control for SYSTEM, Administrators, and the user. If Windows permissions overrule, then by that very statement, doesn't it mean that any chmod done via WSL won't be observed? – Ash Jan 29 at 0:54
  • @Ash, take a look at the options in Basil A's answer. It's possible you need one or both of those masks. I don't know enough about the issue to resolve this. – nilskp Jan 29 at 23:38
9

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 '18 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 '18 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 '18 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 '18 at 19:09
  • 3
    @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 '18 at 21:30
3

The correct way to handle this:

  1. Create a file named /etc/wsl.conf and edit it to contain the following:
    [automount]
    enabled = true
    root = /mnt/
    options = "metadata,umask=22,fmask=11"

To understand the meaning of each parameter above, please refer to this article on msdn: https://blogs.msdn.microsoft.com/commandline/2018/02/07/automatically-configuring-wsl/

  1. Close all open WSL terminal then open a new one.

Now you are all set, changing permissions of a file in windows from /mnt/c/ will be reflected correctly on the Linux Subsystem through the WSL "metadata" feature.

The WSL configuration will always mount correctly on startup of WSL.

  • 1
    Does not work for me. I did exactly as you suggest, but permission set using chmod still do not reflect when doing a ls -al. Strangely enough (and this was also the case prior to doing this change), certain chmod values work while others don't. For e.g, 0600 has no effect but 0400 changes it to -r-xr-xr-x. – Ash Jan 28 at 6:18
  • This answer works well for me. @ArunprasadRajkumar, fmask should not be 111 - using this removes the executable flag from all files by default (which is noted in the article that you link to) and is probably not what you want. Using fmask=11 uses executable flags from the file system by default so works well. – zelanix May 19 at 10:22
  • To clarify my previous comment, fmask=111 removes execution rights from all files for owner, group, and anonymous users. fmask=11 removes execution rights for group and anonymous users only, while using the execution right from the file system for owner (this is probably what you want, and works well with git). umask=22 removes write rights from files and directories for group and anonymous users. – zelanix May 19 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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