“sudo su”不会将环境变量传递给新的shell吗?

“sudo su”不会将环境变量传递给新的shell吗?

su 手册

http://manpages.ubuntu.com/manpages/precise/man1/su.1.html

当前环境被传递给新的 shell。

显然,您不能在 Ubuntu 中使用 su,su但由于 Ubuntu 中的 root 用户是被禁用的,所以必须始终使用 su,sudo su但这似乎改变了 su 命令的能力。

有什么解释吗?

答案1

我想我在某处读到过,sudo 不会故意传递所有环境变量,因为这可能会被用来引入 root 漏洞(与最近的 bash 漏洞类似)。或者您可能需要使用带 -E 的 sudo

 -E, --preserve-env
             Indicates to the security policy that the user wishes to pre‐
             serve their existing environment variables.  The security
             policy may return an error if the user does not have permis‐
             sion to preserve the environment.

因此,您可能在某处设置了不同的“安全策略”。man sudo有更多信息,它似乎具有比仅仅更多的设置su

答案2

su如果您已经通过设置密码启用了 root 用户,则可以直接使用。

这可以通过命令完成

sudo passwd root

相关内容