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)
Currently, the only way I was able to achieve this was to use rmate.
sudo wget -O /usr/bin/rmate https://raw.githubusercontent.com/aurora/rmate/master/rmate
sudo chmod a+x /usr/bin/rmate
I'm using a Debian Buster WSL here, however you can replace /usr/bin
with an appropriate folder in your $PATH depending on your OS or your preference.
make sure the Extension is enabled on WSL: after adding the plugin.
Here is how I configured the remote VS Code plugin
File -> Preferences -> Settings
Press F1 and run Search for the Remote: Start Server
command.
Start your WSL instance and open a terminal. If you've done everything correctly you should be able to now edit your files with sudo priveledges in your editor, even if you are not the root user.
sudo rmate /etc/profile.d/custom-profile.sh