28

Possible Duplicate:
Why do we use su - and not just su?

I understand that root doesn't have to be a superuser. But in the case that it is ... what is the difference between sudo su - and sudo su root?

ripper234
  • 31,763
  • 1
    Never mind google or the man pages, did you search this site for duplicate questions before you asked? The topic is covered here, here and here as well as in passing in a number of questions about the usage of sudo. – Caleb Jun 25 '11 at 09:54
  • @Caleb - I found that question before posting, but that did not answer my direct question. See the second part of @Mat's answer. – ripper234 Jun 26 '11 at 06:07

2 Answers2

29

There are two questions there:

  • Difference between su - username and su username

If - (or -l) is specified, su simulates a real login. The environment is cleared except for a few select variables (TERM notably, DISPLAY and XAUTHORITY on some systems). Otherwise the environment is left as it is except for PATH that is reset.

  • Difference between passing no user name and specifying root

This might be system-dependent. On Linux with shadow as the package providing su, if no username is specified, then su first tries to see if user root has a passwd entry. If it does, it uses that. If it doesn't, it tries uid 0.

Not sure about other Unix-like operating systems.

Mat
  • 52,586
8

su - switches to the superuser and sets up the environment so that it looks like they logged in directly. su root switches to the user named root and doesn't simulate directly logging in.

If the superuser is named root, then su and su root are equivalent (and don't simulate directly logging in), as are su - and su - root (which do).