I tried to switch to 'root' in CentOS by running su
. It does change to 'root', but it doesn't seem to be a real 'root' user.
For example, by default, ifconfig
command in /sbin
is not found in the path for a normal user, but for 'root', the command can be found. When I run su
, I still get bash: ifconfig: command not found
output when I try to run ifconfig
.
However, when I run su -
, ifconfig
just works.
What is the difference between su
and su -
in CentOS?
Adding the
-
option affects your environment behavior. For all practical purposes, the environment is completely reset. In general, you likely want to usesu -
instead of plainsu
. From the man page:su -
invokes a login shell, which among other things, ensures that root's.bashrc
and other shell startup scripts are run, just like as if you'd logged in directly as root via console or SSH. root's profile usually sets your path to include/sbin
which is whereifconfig
generally lives.