简体   繁体   English

防止 VSCode 从 WSL 以 root 身份打开

[英]Prevent VSCode opening as root from WSL

When opening VSCode in a folder using code.使用code. using my current user, I notice that then it was started as root.使用我当前的用户,我注意到它是以 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 (在此之后,在 VSCode 的终端内) $ 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:另一个奇怪的事情是 VSCode 终端似乎加载了我用户的 .zshrc,这仍然在 VSCode 终端内:

  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 ?为什么要对不是来自输出$ whoami的用户的目录进行$ cd更改? How do I force VSCode to open as the same user as in WSL?如何强制 VSCode 以与 WSL 中相同的用户身份打开?

Another detail: when creating files inside the same folder, using the VSCode GUI, those are also created as root:另一个细节:在同一文件夹内创建文件时,使用 VSCode GUI,这些文件也被创建为 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:在 windows 端运行以下命令为我解决了这个问题:

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

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

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