简体   繁体   中英

Prevent VSCode opening as root from WSL

When opening VSCode in a folder using code. using my current user, I notice that then it was started as root. The steps that I'm making are to validate this behaviour are:

  1. $ whoami
    >> franciscoserrano
  2. $ mkdir test-dir && ll
    >> drwxr-xr-x 2 franciscoserrano franciscoserrano 4.0K Jan 18 19:04 test-dir
  3. $ cd test-dir
  4. $ code.
  5. (right after this, inside VSCode's terminal) $ pwd && whoami
/home/franciscoserrano/projects/test-dir
root

Another weird thing is that the VSCode terminal seems to load the.zshrc of my user, this is still inside VSCode terminal:

  1. $ pwd
    >> /home/franciscoserrano/projects/test-dir
  2. $ whoami && cd
    >> root
  3. $ pwd
    >> /home/franciscoserrano

Is this intended? Why making $ cd changes to a directory that is not from the user that outputs $ whoami ? How do I force VSCode to open as the same user as in WSL?

Another detail: when creating files inside the same folder, using the VSCode GUI, those are also created as root:
-rw-r--r-- 1 root root 0 Jan 18 19:18 hello.c

Running the following command on the windows side fixes this issue for me:

ubuntu2204.exe config --default-user <wsl-user>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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