Server Fault is a question and answer site for system and network administrators. 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

What is the difference between these 2 options in /etc/sudoers:

user1 mymachine = (user2) ALL

user1 mymachine = /bin/su - user2

For option 1, I would do the following as user1:

sudo -u user2 -i

For option 2, I would do the following as user1 (this option also requires "Defaults !authenticate" so that it doesn't ask for a password):

sudo su - user2

Is there any pros/cons to either method? The end result seems the same.

share|improve this question

Both commands will give you same result, but they are different:

In the case of "sudo -u user2 -i" you will get complete initial environment of that "user2", like an initial logged in state of that another user.

In the case of "sudo su - user2" you will get environment variables of the user1 preserved. But IMHO using sudo su to me is as bad as "grep | awk"

share|improve this answer
If you use "sudo su - user2" you still get the environment of user2, because of the "-". But you'd say that "sudo -u" is more proper? – Logan McNaughton Oct 4 '13 at 14:03
"sudo su - user2" will get the environment of user2, but not completely, it will get everything of user2 except for HOME, SHELL, PATH, TERM, and USER. USER is set to the target login. PATH is set to ``/bin:/usr/bin''. TERM is imported from your current environment. – Danila Ladner Oct 4 '13 at 14:09

Your Answer


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.