CentOS 中的 `su` 和 `su -` 有什么区别?

PJ.*_*PJ. 7 linux centos root users

我试图通过运行su. 它确实更改为“root”,但它似乎不是真正的“root”用户。

例如,默认情况下,普通用户在路径中找不到ifconfigcommand in /sbin,但是对于'root',可以找到该命令。当我运行时subash: ifconfig: command not found当我尝试运行时仍然得到输出ifconfig

但是,当我运行时su -ifconfig就可以了。

CentOSsusu -CentOS 中有什么区别?

Sco*_*ack 16

添加该-选项会影响您的环境行为。出于所有实际目的,环境已完全重置。通常,您可能希望使用su -而不是普通的su. 从手册页:

 -l      Simulate a full login.  The environment is discarded except for HOME, SHELL, PATH, TERM, and USER.  HOME and SHELL are modified as above.
         USER is set to the target login.  PATH is set to ``/bin:/usr/bin''.  TERM is imported from your current environment.  The invoked shell is
         the target login's, and su will change directory to the target login's home directory.

 -       (no letter) The same as -l.
Run Code Online (Sandbox Code Playgroud)


vio*_*let 6

su -调用登录 shell,其中包括确保 root.bashrc和其他 shell 启动脚本运行,就像您通过控制台或 SSH 直接以 root 身份登录一样。根的个人资料通常设置路径,以包含/sbin这也正是ifconfig通常过着。