简体   繁体   English

无法保存根 WSL2 VSCODE 拥有的文件

[英]Unable to save files owned by root WSL2 VSCODE

I have a project that the files are owned by root, for example:我有一个文件由 root 拥有的项目,例如:

> ls -la
-rw-r--r--  1 root   root     36 May  6 20:57 README

and the project is inside a WSL2 and I am using VSCODE.并且该项目在 WSL2 内,我正在使用 VSCODE。 When I am trying to save a change I get the following error message:当我尝试保存更改时,我收到以下错误消息:

Failed to save 'README': Unable to write file 'vscode-remote://wsl+centos7/home/foteas/code/AppSrc/README' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/home/foteas/code/AppSrc/README')

I do not want to change the ownership of the files or the folders.我不想更改文件或文件夹的所有权。 Is there any way to edit the file as root via the VSCODE?有没有办法通过 VSCODE 以 root 身份编辑文件?

It's a known issue.这是一个已知问题。 There are a few workarounds proposed in the github issue here . github issue here中提出了一些解决方法。

From Xunnamius on github:来自 github 上的 Xunnamius:

Rather than enter a security nightmare with root ssh logins and running code as root, I created acl-enable-for and acl-disable-for simple little scripts taken from the solutions above.我没有使用 root ssh 登录并以 root 身份运行代码,而是为从上述解决方案中提取的简单小脚本创建了acl-enable-foracl-disable-for ,而不是进入安全噩梦。

For example, I run acl-enable-for /etc/nginx and make a note to run acl-disable-for /etc/nginx later.例如,我运行acl-enable-for /etc/nginx并记下稍后运行acl-disable-for /etc/nginx Note that acl-disable-for deletes all ACLs on a path recursively.请注意, acl-disable-for会递归删除路径上的所有ACL。

You may have to replace $USER with your literal username in the command below您可能需要在下面的命令中将 $USER 替换为您的文字用户名

/usr/local/bin/acl-enable-for : /usr/local/bin/acl-enable-for

 #?/usr/bin/env bash # * Enables a read/write ACL on the chosen path(s) recursively set -e #; Ensure we're running as root if [[ `id -u` -ne 0 ]]: then echo 'acl-enable-for: please run as root:' exit 1 fi set +e setfacl -R -mu:$USER:rwx "$@" # setfacl -R -mu:$USER:rw "$@" # a bit more restrictive

/usr/local/bin/acl-disable-for : /usr/local/bin/acl-disable-for

 #?/usr/bin/env bash # * Clears all ACLs on a chosen path recursively set -e #; Ensure we're running as root if [[ `id -u` -ne 0 ]]: then echo 'acl-disable-for: please run as root!' exit 1 fi set +e setfacl -Rb "$@"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM