WSL中的VSCode:如何对根文件进行sudo,以便我可以对其进行编辑 [英] VSCode in WSL: how to sudo a root file so I can edit it

查看:1475
本文介绍了WSL中的VSCode:如何对根文件进行sudo,以便我可以对其进行编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WSL v.1-VSCode v1.40.1(使用"Remote-WSL"扩展名40.3)

WSL v.1 -- VSCode v1.40.1 (using 'Remote - WSL' extension 40.3)

如何使用sudo和VSCode打开root拥有的文件进行编辑? (无需以root身份运行)

如果我打开不带sudo的根文件,则无法对其进行编辑(预期): $代码/etc/profile.d/custom-profile.sh $

If I open a root file without sudo, I can't edit it (expected): $ code /etc/profile.d/custom-profile.sh $

但是,如果我尝试sudo code该文件,则会得到:

But, if I try to sudo code the file, I get:

$ sudo code /etc/profile.d/custom-profile.sh
[sudo] password for xxxx:
sudo: code: command not found

下面的Binarify回答表明,我可以将默认用户切换为root,但是我绝对不希望以root用户身份运行,因此我仍在寻找另一种解决方案.

Binarify's answer below shows that I can switch the default user to root, but I definitely don't want to be running as root, so I'm still looking for another solution.

推荐答案

您可以拥有要编辑的文件,然后再将其归还所有权

You can own the file you want to edit, then give it back the ownership afterwards

sudo chown myuser /path/to/file
code /path/to/file
sudo chown root /path/to/file

这篇关于WSL中的VSCode:如何对根文件进行sudo,以便我可以对其进行编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆