无法在 VS Code 终端中运行 sudo

Sia*_*ore 8 sudo visual-studio-code

当尝试以 sudo 身份运行命令时,出现错误

sudo: The "no new privileges" flag is set, which prevents sudo from running as root.
sudo: If sudo is running in a container, you may need to adjust the container configuration to disable the flag.
Run Code Online (Sandbox Code Playgroud)

我没有运行任何容器,并且 sudo 在默认终端中工作正常。

我找到了此页面,但没有关于如何取消设置此标志的说明:https://manpages.ubuntu.com/manpages/jammy/en/man8/sudo.8.html

Est*_*her 10

这里的问题是 VS Code 会自行沙箱,以防止错误(或恶意扩展等)提升权限并可能损害您的系统。因此,它启动的任何进程(包括sudo终端中的进程)都不会以 PID 0 启动并成为根进程。

您可以使用该标志启动 vscode--no-sandbox来禁用此沙箱。这将允许 vscode 启动的进程以 root 身份运行,并允许您sudo在 vscode 终端中使用。然而,这确实会让您的系统更容易受到攻击,因为无法以 root 身份运行进程是出于安全目的而故意做出的设计决策。