WSL v.1 -- VSCode v1.40.1 (using 'Remote - WSL' extension 40.3)
How to open a root-owned file for edit using sudo and VSCode? (without running as root)
If I open a root file without sudo
, I can't edit it (expected):
$ code /etc/profile.d/custom-profile.sh
$
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'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