I created a server program that will be started as root. After it is started I want to drop privileges to another user. How can I do this securely?
See Privileges::Drop.
You don't really need a module, although the one linked by Benji York looks pretty nice.
It's a simple matter of setting the UID via $<
and $>
. See perlvar for further information on these. You can also set the GID this way using $(
and $)
; note that you need to set $) = "$target_gid $target_gid"
if you want to drop supplemental groups. Don't forget to test for success afterwards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With