WSL: mkdir command has wrong permissions

  • A brief description

The default mkdir setting creates a folder with Read, Write, Execute permissions for Owner, Group and World (0777). On other systems, mkdir creates a folder with Read, Write, Execute permissions for Owner and Read permissions for Group and World (0755).

This caused test failures running the https://github.com/apple/swift-llbuild project (part of Swift.org)

# command stderr:
/mnt/c/Users/hughb/Documents/GitHub-WSL/swift-llbuild/tests/BuildSystem/Build/mkdir.llbuild:15:22: error: expected string not found in input
# CHECK-PERMISSIONS: 0755
                     ^
/mnt/c/Users/hughb/Documents/GitHub-WSL/build/tests/BuildSystem/Build/Output/mkdir.llbuild.tmp.permissions:1:1: note: scanning from here
0777
^
  • Expected results

drwxr-xr-x 2 root root 0 Mar 23 16:35 foo

  • Actual results (with terminal output if applicable)

drwxrwxrwx 2 root root 0 Mar 23 16:35 foo

  • Your Windows build number

14393.953

  • Steps / All commands required to reproduce the error from a brand new installation

mkdir foo ls -l

  • Strace of the failing command

N/A

  • Required packages and commands to install

N/A

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 9
  • Comments: 20 (3 by maintainers)

Most upvoted comments

Yeah there’s a couple unrelated things going on here making it confusing. One is file permissions on DrvFs (/mnt/c), which are now supported in WSL as of Insider 17063 and Spring Creators real soon now. If the drive isn’t mounted with the ‘metadata’ feature, directories are going to take on the permissions of the mount regardless of your umask.

The other is the default umask, which is still 0000 (causing a 777 mkdir). That is #352 and is still open. There are work-arounds over there, the easiest being to set the umask in your .profile/.bashrc/.zshrc/.whateverrc.

This thread was really confusing. It seems several people redirected here from other threads (though not OP) and I are experiencing the issue that even in /home/our_username, mkdir still makes with 777 permissions. umask returns 0000. Was there ever a clear answer to this @therealkenc ?

I think what everyone wants to know at this point is WHERE to set umask 022 so that WSL stops creating directories with 777 instead of 755.

The improper settings BREAK things like oh-my-zsh, antigen, and other zsh stuff.

An after-the-fact solution would be to run a compaudit then find $COMMON_PATH_OF_THOSE_DIRECTORIES -type d -exec chmod 0755 {} \;

Overall, it would be nice if WSL had the umask 022 mask enabled by default and simple “put that in [insert file name here].”

Because the next problem after that would be finding out why nice(5) denies permissions to do things. It could be for the same reason. (Follow up: It’s issue #1887. Just need to add unsetopt BG_NICE near the beginning of ~/.zshrc.)

The default umask on Ubuntu is 0222 (http://askubuntu.com/questions/44542/what-is-umask-and-how-does-it-work)

Manually setting umask on the command line

Unfortunately, mkdir on WSL seems to ignore any umask you set: mkdir-umask-set

umask 22
mkdir foo1
ls -l

Manually passing the mode on the command line

Unfortunately, mkdir on WSL seems to ignore any -m parameter you pass: mkdir-mode

mkdir -m 755 foo2
ls -l