WSL 文件操作提示: Operation not permitted

在 Windows 子系统上 git clone 库到 /mnt/x/codes 时提示 failed: Operation not permitted

shell
1
2
3
4
$ git clone https://github.com/ehang-io/nps.git
Cloning into 'nps'...
error: chmod on /mnt/c/codes/nps/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'

怀疑是文件权限问题,使用 sudo 命令能够 clone 成功

shell
1
2
3
4
5
6
7
8
9
10
$ sudo git clone https://github.com/ehang-io/nps.git
[sudo] password for akiya:
Cloning into 'nps'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 5635 (delta 3), reused 3 (delta 1), pack-reused 5626
Receiving objects: 100% (5635/5635), 8.80 MiB | 4.98 MiB/s, done.
Resolving deltas: 100% (3145/3145), done.
Updating files: 100% (168/168), done.

但是查看其它文件发现权限全是 777,感觉有点奇怪,查阅文档后得知是由于文件权限问题导致的,添加配置 /etc/wsl.conf 内容如下,添加后重启可以发现文件权限正常了

/etc/wsl.conf
1
2
3
4
[automount]
enabled = true
options = "metadata,umask=22,fmask=11"
mountFsTab = false

参考文章:

评论

:D 一言句子获取中...

加载中,最新评论有1分钟缓存...