Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

marked as duplicate by Caleb, Gilles, camh, Michael Mrozek Jun 25 '11 at 18:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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 9: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 6:07
up vote 21 down vote accepted

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.

share|improve this answer

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).

share|improve this answer

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