I need a tool that would be run by root, drop root by switching to another user, and then execute another program specified by the command line argument(s). Use case: run something from a (custom) init scripts under a non-privileged user.
I want to avoid using su
or sudo
because they serve a different purpose (provide an interactive way of becoming root for non-privileged users), are much more complex than needed for this task, change behaviour depending on various configuration files, and write stuff to syslog.
Is there such a tool available?
Update: I found an answer buried deep on stackoverflow: it's setuidgid
from daemontools (or s6-setuidgid
from s6). Apparently, the author(s) of daemontools had some reasons not to use su
for running daemons, as well.
The only drawback is that setuidgid
remains running along with the program it launched. Ideally I'd prefer it to exec
instead of spawn
/fork
to keep the process table cleaner, but it's not that much of an issue.