Super User is a question and answer site for computer enthusiasts and power users. 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

It is my understanding that they do the same: they ask for my password (if I am allowed in /etc/sudoers), and give me a login shell as root.

Is there any difference between them?

sudo su -
sudo -i

Also, what's the difference between

sudo su
sudo -s

I think that they both ask for my password, and give me a shell with my old environment variables.

share|improve this question
up vote 4 down vote accepted

There is little difference in the command pairs you are wondering about.

The first pair attempts to simulate a fresh login as the new user-- there could be some difference in the environmental variables supplied, as sudo su - is going to try and preserve existing environmental variables, while sudo -i will set very specific environmental variables and strip all others (check your man pages for specifics).

For the second pair, the difference in behavior is this: sudo su will always start the shell listed in the user's /etc/passwd, whereas sudo -s will check the SHELL environmental variable first, and only execute the shell in /etc/passwd if SHELL is unset.

share|improve this answer
Note that the set of variables preserved by "su -"/"sudo su -" is also very restricted, maybe similar to what sudo -i does. – Stéphane Gimenez Jul 23 '11 at 17:55
sudo su - is going to try and preserve existing environmental variables ? I read that su - makes the shell a login shell & changes the environmental variables to those of the new user source – A.D. May 24 '13 at 13:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .