Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 3 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

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.