5

解决 WSL 的文件权限问题

 2 years ago
source link: https://www.codewoody.com/posts/57316/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Published Mar 06, 2022

解决 WSL 的文件权限问题

本文旨在解决在 Windows 10/11 中使用 Windows Subsystem for Linux (WSL) 时,位于宿主 Windows 操作系统的中的文件被挂在到 Linux 系统内部时权权限紊乱的问题。一般情况下,宿主机上的文件在虚拟机内部看起来都是 777 权限;

本文转载自:Fix Windows Subsystem for Linux (WSL) File Permissions

这是由于 WSL 的默认挂载机制导致,我们可以通过 /etc/wsl.conf 文件来配置 WSL 的文件挂载行为。注意这个文件默认情况时不存在的,需要你手动创建。在这个文件里面放入下面的内容:

[automount]
enabled = true
options = "metadata,umask=22,fmask=111"

然后在 ~/.profile 中加入下面的内容:

# Note: Bash on Windows does not currently apply umask properly.
if [[ "$(umask)" = "0000" ]]; then
umask 0022
fi

用来替换 WSL 中非常糟糕的 umask 默认值。

需要注是,在做完以上修改后,你之前使用的 VSCode WSL 远程开发功能可能会无法连接上 WSL。这是因为 VSCode 所以来的 WSL 的内部脚本 /mnt/c/Users/your_username/.vscode-insiders/extensions/ms-vscode-remote.remote-wsl-0.42.0/scripts/wslServer.sh 将会失去原本 WSL 默认设定的可执行权限,需要你在 WSL 内部手动给这些文件添加 +x 权限。这可以通过在 WSL 内部调用 chmod 命令来实现。

Weekly-84 - 寻找小花梅


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK