I have a process that gets started by a damon running as root, now I want to "downgrade" this process's privileges to those of your average user. Is this possible? If yes how?
PS: Running unix on a mac
|
I have a process that gets started by a damon running as root, now I want to "downgrade" this process's privileges to those of your average user. Is this possible? If yes how? PS: Running unix on a mac |
||||
|
|
|
The process itself has to call setuid(2). You should also investigate running it inside chroot(8) if you arent already. As far as I know there is no way for root to change the uid of another process. If the reason you are running it as root is to bind ports I'd suggest running it as a normal user on a higher port and using ipfw(8) on OS X to forward port 80/443/etc to the higher port: http://support.crashplanpro.com/doku.php/recipe/forward_port_443_to_pro_server_on_mac_osx |
|||||||||||
|
|
|
|||
|
|
You can run commands as other users using
Will run Note that, by default, |
|||||||||||
|
|
To drop privileges, you need a non-root user to drop to. Then it's just a matter of switching to that user:
Note that this is done within the program itself, rather than in a wrapper script. Many programs require root privileges for some specific purpose (e.g. to bind to a low-numbered port), but don't need root after that. So these programs will start as root, but then drop privileges once they're no longer needed. If you don't need root privileges at all, then just don't run it as root. E.g.:
|
|||||||||||||
|
|
If you're executing a different executable, i.e. you're calling
If the child process needs to start as root but drop privileges later, see the code in this answer, which illustrates how to downgrade privileges in a process. |
|||
|
|