Default permission and ownership in WSL

北战南征 提交于 2020-06-17 09:31:11

问题


I'm currently in the process of switching from an Ubuntu 18.04 VirtualBox to the WSL. Everything is up and running to have a complete web dev environment. Unfortunately, the file permission and ownership is kind of a problem for me right now.

--- Disclaimer--- I know that in a server environment this would be pretty bad and wouldn't be done. This is just for my local development process and this requirement will stay there.

What I want to achieve is, to have a consistent set of permissions and ownerships within my /var/www (and all below).

  • Every element within /var/www should be owned by my shell user, regardless if file or dir.
  • Every element should have the group www-dataso that the webserver user have access.
  • Each file should have permission 0664 and each directory 0775.
  • every new element should follow these requirements.

What I researched so far: If I make a new directory/ file from the shell or within VSCode, my user and group are used. If I make a new directory from the windows explorer, the ownership is root:root. Nevertheless, I also have to figure out how to set default permissions for new objects.

I just want an easy to use way to CRUD my files from anywhere I am on my system.

Is there anyone with an idea for this?

Thanks a lot, Danaq.

Edit: It would also be ok, to set everything to www-data:ww-data and add my shell user to the www-data-group if the permissions are applied like explained above.


回答1:


For everyone encountering the same issue and find this question:

Under ~[USER~/.profile I uncommented the umask-property and set it to 002. This will, according to this guide, set all new created file to 0664 and all new directories to 0775.

I then added the www-data-user to the group of my shell-user with

sudo usermod -a -G www-data [GROUP].

So now, every file I'm creating is owned by and within the group of my shell user. But it can be red by the www-data-user too. This should lead to not always using the

find ./ -type d -exec chmod 775 {} \;

the command to set the right permissions on all directories of a web project after migration for example.

This solution does only help, if the files and directories are created from the WSL-bash. If you are using the explorer or trying to create a file from the VSCode-terminal, the default umask of 022 will be still applied.




回答2:


According to this, newer versions of the Remote-WSL server, when they get started will execute (if present):

  • ~/.vscode-server/server-env-setup
  • ~/.vscode-server-insiders/server-env-setup

(more on that)

So a solution is to execute:

# this will affect folders created from the editor
mkdir -p ~/.vscode-server/ && echo "umask 002" >> ~/.vscode-server/server-env-setup
mkdir -p ~/.vscode-server-insiders/ && echo "umask 002" >> ~/.vscode-server-insiders/server-env-setup

# this will affect folders created from terminals
echo "umask 002" >> ~/.bashrc


来源:https://stackoverflow.com/questions/60250668/default-permission-and-ownership-in-wsl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!