WSL 中的默认权限和所有权 [英] Default permission and ownership in WSL
问题描述
我目前正在从 Ubuntu 18.04 VirtualBox 切换到 WSL.一切都已启动并运行,以拥有一个完整的 Web 开发环境.不幸的是,文件权限和所有权现在对我来说有点问题.
--- 免责声明---我知道在服务器环境中这会很糟糕并且不会完成.这仅适用于我的本地开发过程,此要求将保留.
我想要实现的是,在我的/var/www(以及以下所有内容)中拥有一组一致的权限和所有权.
- /var/www 中的每个元素都应该归我的 shell 用户所有,无论是文件还是目录.
- 每个元素都应该有
www-data
组,以便网络服务器用户可以访问. - 每个文件应该有权限
0664
和每个目录0775
. - 每个新元素都应遵循这些要求.
我目前研究的内容:如果我从 shell 或在 VSCode 中创建一个新目录/文件,则会使用我的用户和组.如果我从 Windows 资源管理器创建一个新目录,所有权是 root:root
.尽管如此,我还必须弄清楚如何为新对象设置默认权限.
我只是想要一种易于使用的方法,可以从我系统上的任何位置对我的文件进行 CRUD.
有人对此有想法吗?
非常感谢,达纳克.
也可以,将所有内容设置为 www-data:ww-data
并将我的 shell 用户添加到 www-data
-group 如果如上所述应用权限.
根据 this,Remote-WSL 服务器的较新版本,当它们启动时将执行(如果存在):
~/.vscode-server/server-env-setup
~/.vscode-server-insiders/server-env-setup
所以解决方案是执行:
# 这将影响从编辑器创建的文件夹mkdir -p ~/.vscode-server/&&回声umask 002">>~/.vscode-server/server-env-setupmkdir -p ~/.vscode-server-insiders/&&回声umask 002">>~/.vscode-server-insiders/server-env-setup# 这将影响从终端创建的文件夹回声umask 002">>~/.bashrc
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-data
so that the webserver user have access. - Each file should have permission
0664
and each directory0775
. - 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.
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
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
这篇关于WSL 中的默认权限和所有权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!