文章目录

  • 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解决方法相关推荐

  1. open failed: EACCES(Permission denied)解决方法

    open failed: EACCES(Permission denied)解决方法 异常现象: 在manifest文件中已经添加权限而且Android系统为5.0.2. <uses-permi ...

  2. bash: ./xx: Permission denied解决方法

    这是权限不足的原因,切换成管理员也没有用. 为了获得执行权限,借助chmod指令修改文件权限即可 sudo chmod 777 xxx 其中777是111,111,111,即获得可读可写可执行权限 之 ...

  3. Linux permission denied解决方法

    Linux permission denied解决方法 参考文章: (1)Linux permission denied解决方法 (2)https://www.cnblogs.com/aarontho ...

  4. zabbix报错cannot set resource limit: [13] Permission denied解决方法

    zabbix报错cannot set resource limit: [13] Permission denied解决方法 参考文章: (1)zabbix报错cannot set resource l ...

  5. SVN报错:can‘t open file db/txn-current-lock:permission denied 解决方法

    SVN报错:can't open file db/txn-current-lock:permission denied 解决方法 参考文章: (1)SVN报错:can't open file db/t ...

  6. 用cygwin从本地向ubuntu某路径下传文件时Permission denied解决方法

    ubuntu系统的虚拟机安装了ssh服务,windows系统的本机安装了cygwin. cygwin下向ubuntu的/usr/local下传输文件jdk-8u191-linux-x64.tar.gz ...

  7. touch: cannot touch /usr/local/tomcat/logs/catalina.out: Permission denied解决方法

    一.报以下错误: Using CATALINA_BASE: /home/apache-tomcat-7.0.72 Using CATALINA_HOME: /home/apache-tomcat-7. ...

  8. ftp 530 linux,Linux启动ftp服务器530 Permission denied解决方法

    重新在虚拟机下安装了linux.现在我想启动linux自带的ftp服务器:#service  vsftpd  start .如果想linux启动是自动启动ftp服务器:#chkconfig  vsft ...

  9. SVN报错:can't open file db/txn-current-lock:permission denied 解决方法

    现象: SVN服务器重启后,重新挂载SVN仓库,可以下载代码,但是上传代码发现报错:can't open file db/txn-current-lock:permission denied 刚开始以 ...

最新文章

  1. 《你不知道的JavaScript》整理(四)——原型
  2. 新手建站注意点,你有注意到没?
  3. 计算机思维能力培养的核心是什么,计算机基础教学的核心任务是计算思维能力的培养[J]...
  4. 听云支持.NET Core的应用性能监控
  5. 阿里巴巴大数据实践—阿里巴巴的数据模型实践综述
  6. java抛出异常thorw和throws的用法
  7. Linux 网络配置 修改DNS配置文件/etc/resolv.conf后,重启网络,DNS配置丢失
  8. android 找不到密钥,InvalidKeyException:在Android设备上进行RSA解密时密钥库操作失败...
  9. 信息系统基础知识---企业信息化与电子商务
  10. ssh远程连接虚拟机
  11. ps 抠图 修改背景颜色
  12. unity3d android访问剪贴板,Airtest 和 poco 的 swipe 接口使用总结
  13. 单片机计时器100000秒以内
  14. 洛谷P5633 最小度限制生成树 题解
  15. 【英语】很抱歉,我一天的86400秒却没有你
  16. Thinkphp5威客任务平台网站源码
  17. 原型模式【浅克隆实现,使用序列化实现深克隆】Java代码演示
  18. phpip地址查询_PHP获取IP地址所在的地理位置
  19. BB10 Cascades Hello World样例分析
  20. linux回环网卡,Linux回环网卡驱动设计

热门文章

  1. java List/ArrayList 解惑
  2. 用GATK进行二代测序数据 SNP Calling 流程:(二)bwa比对和HaplotypeCaller 变异检测
  3. 科技战疫志愿精神如何延续?腾讯的答案是……
  4. Cisco:DHCP自动获取IP地址
  5. CANopen协议基础知识
  6. [Linux命令] Cat是一只可爱的猫
  7. 4.1 c++左值和右值、类型转换
  8. lilypond 符号_LilyPond演奏优美的音乐
  9. 一圆形游泳池如图所示,现在需在其周围建一圆形过道,并在其四周围上栅栏。栅栏价格为35元/米,过道造价为20元/平方米。过道宽度为3米,游泳池半径由键盘输入。要求编程计算并输出过道和栅栏的造价。
  10. CVE-2017-8570微软office漏洞复现与研究