bash - chmod WSL (Bash) 不起作用

标签 bash windows-10 chmod windows-subsystem-for-linux

在 Windows 10 上运行 bash,下面的简单语法在我通过 SSH 连接到我的网络服务器时有效,但在我退出并在我的本地计算机上时无效。它没有给我一个错误,但我可以看到权限没有改变。我必须检查我是否在计算机上设置为管理员。这是错误还是仅仅是本地操作系统是 Windows 的结果?如果是后者,如果像这样的常见操作不起作用,这让我质疑在 Windows 上使用 bash 的值(value)。

$chmod 644 filename 

最佳答案

要启用更改文件所有者和权限,您需要编辑 /etc/wsl.conf 并插入以下配置选项:

[automount]
options = "metadata"

在 WSL shell 中执行此操作,可能需要 sudo 来编辑/创建文件。

这可能需要重新启动 WSL(例如使用 wsl --shutdown,这是一个 Windows 命令,而不是 WSL 中的命令)或主机才能生效。自 2018 年以来,这是可能的:

You can now set the owner and group of files using chmod/chown and modify read/write/execute permissions in WSL. You can also create special files like fifos, unix sockets, and device files. We’re introducing new mounting options with DrvFs for projecting permissions onto files alongside providing new Linux metadata on files and folders.

[引用:Microsoft Dev Blog ]


您还可以使用以下命令临时重新安装驱动器:

sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata

...但请注意,该命令仅在 session 范围内生效。如果您退出当前的 bash,您将丢失您的设置(来源:回答者 Amade)。


引用:

Automatically Configuring WSL

关于bash - chmod WSL (Bash) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46610256/

相关文章:

使用变量在 C 文件中调用 bash 命令

bash - Electron 在 Windows bash 上开箱即用

c# - Win10 构建 : Loading assembly failed

linux - CHMOD 设置隐藏目录

python-3.x - 使用 python filename.py 执行时没有名为 psutil 的模块,但与 shebang & chmod 完美配合

bash - 使用 grep 查找文件并在编辑器中打开

bash - 命令替换后的管道状态

Git CHMOD 接收后 Hook

bash - 在 WSL 上从 Bash 打开 Sublime Text

python - 让 Scapy 在 Windows 上工作时出错 : "' module' object has no attribute 'ex_name' "