Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default permission and ownership in WSL

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.

like image 406
Danaq Avatar asked Sep 06 '25 03:09

Danaq


1 Answers

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
like image 136
Francesco Galisi Avatar answered Sep 09 '25 04:09

Francesco Galisi