wsl2使用vscode无法写入文件permission denied解决方法
文章目錄
- Problem
- Solution
- Reference
- 總結
Problem
Come cross a problem in wsl2 to use vscode.
未能保存“settings.json”: 無法寫入文件/code/.vscode/settings.json(NoPermissions (FileSystemError): Error: EACCES: permission deniedSolution
In official documentation, I found this:
在stackoverflow上,看到的這個解決方法
在/etc下面新建wsl.conf文件,然后對其進行配置
官方文檔(參考鏈接)中復制出來:
# Automatically mount Windows drive when the distribution is launched [automount]# Set to true will automount fixed drives (C:/ or D:/) with DrvFs under the root directory set above. Set to false means drives won't be mounted automatically, but need to be mounted manually or with fstab. enabled = true# Sets the directory where fixed drives will be automatically mounted. This example changes the mount location, so your C-drive would be /c, rather than the default /mnt/c. root = /# DrvFs-specific options can be specified. options = "metadata,uid=1003,gid=1003,umask=077,fmask=11,case=off"# Sets the `/etc/fstab` file to be processed when a WSL distribution is launched. mountFsTab = true# Network host settings that enable the DNS server used by WSL 2. This example changes the hostname, sets generateHosts to false, preventing WSL from the default behavior of auto-generating /etc/hosts, and sets generateResolvConf to false, preventing WSL from auto-generating /etc/resolv.conf, so that you can create your own (ie. nameserver 1.1.1.1). [network] hostname = DemoHost generateHosts = false generateResolvConf = false# Set whether WSL supports interop process like launching Windows apps and adding path variables. Setting these to false will block the launch of Windows processes and block adding $PATH environment variables. [interop] enabled = false appendWindowsPath = false# Set the user when launching a distribution with WSL. [user] default = DemoUser# Set a command to run when a new WSL instance launches. This example starts the Docker container service. [boot] command = service docker start但是完全照抄會有如下問題,只怪自己沒有仔細閱讀。
PS E:\shizheng_coding\software_design_venkat\reference_text_books\book_code_functional_prog_Java_venkat> wsl <3>init: (278) ERROR: CreateProcessEntryCommon:336: getpwnam(DemoUser) failed 0 <3>init: (278) ERROR: CreateProcessEntryCommon:517: chdir(/e/shizheng_coding/software_design_venkat/reference_text_books/book_code_functional_prog_Java_venkat) failed 13其實,需要將上面官方文檔中的配置修剪一下,只剩下自己需要的上面的報錯就會消失
# Automatically mount Windows drive when the distribution is launched [automount]# Set to true will automount fixed drives (C:/ or D:/) with DrvFs under the root directory set above. Set to false means drives won't be mounted automatically, but need to be mounted manually or with fstab. enabled = true# DrvFs-specific options can be specified. options = "metadata,umask=22,fmask=11"# Sets the `/etc/fstab` file to be processed when a WSL distribution is launched. mountFsTab = true這里的核心點是 all newly created files will use umask 22 (chmod 775) and fmask 11 (chmod 644),意思是所有新創建的文件都可以有775的權限,可讀可寫。
然后我把之前permission denied的文件:.vscode/settings.json 刪掉了
sudo rm -r .vscode/然后重新運行java項目,會生成新的json文件,此時不會報錯
Reference
https://stackoverflow.com/questions/61973385/vscode-unable-to-save-files-inside-my-wsl2-home-folder
https://docs.microsoft.com/en-us/windows/wsl/file-permissions
總結
遇到問題,解決之,記錄之,經驗重復使用,以免重蹈覆轍,反復踩坑。
總結
以上是生活随笔為你收集整理的wsl2使用vscode无法写入文件permission denied解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【项目实战】Python基于孤立森林算法
- 下一篇: 程鑫峰:3.1余威未散鲍威尔再度归来,伦