日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

wsl2使用vscode无法写入文件permission denied解决方法

發布時間:2024/1/8 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 denied

Solution

In official documentation, I found this:

在stackoverflow上,看到的這個解決方法
在/etc下面新建wsl.conf文件,然后對其進行配置

cd /etc sudo vim wsl.conf 然后就是vim中復制進去信息(可見下文)即可 主要的是文件的權限的配置

官方文檔(參考鏈接)中復制出來:

# 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解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。