Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I tried to switch to root in CentOS by running su, but 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?

share|improve this question
4  
It's not just CentOS; it's like this on all Unix-like systems. –  gbarry Jan 31 '10 at 6:33

2 Answers 2

up vote 15 down vote accepted

Adding the - option affects your environment behavior. For all practical purposes, the environment is completely reset. In general, you likely want to use su - instead of plain su. From the man page:

 -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.
share|improve this answer

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 where ifconfig generally lives.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.