Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

in an startup-script that is typically being run as user root, i would like to start a program (actually, a server) as a less-privileged user.

the script originally used

      su -s /bin/sh -c "umask 026; unset HOME; /usr/bin/fooserver" foouser

then a user reported problems with the su approach (in a complicated PAM setup using automounts and whatnot), and suggested to use sudo instead:

      sudo -s /bin/sh -c "umask 026; unset HOME; /usr/bin/fooserver" -u foouser

now i wonder:

  • are these two approaches functionally equivalent?

  • are there any pitfalls i ought to be aware when using sudo -u instead of su? (think: environment preservation)

i'm aware that there are zillions of questions (and answers) regarding the differences between su and sudo, but it seems that all of them are asked from a user perspective (whereas i am using these programs as root)

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.