0

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.

1 Answer 1

1

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"

2
  • 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? Oct 4, 2013 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. Oct 4, 2013 at 14:09

You must log in to answer this question.

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