我试图通过运行su在CentOS中切换到“root”。 它确实变成了“根”,但它似乎并不是真正的“根”用户。
例如,缺省情况下,在普通用户的path中找不到/sbin ifconfig命令,而对于“root”,则可以find该命令。 当我运行su ,我仍然得到bash: ifconfig: command not found输出,当我尝试运行ifconfig 。
但是,当我运行su - , ifconfig只是工作。
su和su -在CentOS上有什么区别?
添加-选项会影响您的环境行为。 出于所有实际的目的,环境完全重置。 一般来说,你可能想用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.
su -调用一个loginshell,除此之外,它确保运行root的.bashrc和其他shell启动脚本,就像直接以root身份通过控制台或SSHlogin一样。 root的configuration文件通常将你的path设置为include /sbin ,这是ifconfig通常所在的地方。