Services default to starting as root
at boot time on my RHEL box. If I recall correctly, the same is true for other Linux distros which use the init scripts in /etc/init.d
.
What do you think is the best way to instead have the processes run as a (static) user of my choosing?
The only method I'd arrived at was to use something like:
su my_user -c 'daemon my_cmd &>/dev/null &'
But this seems a bit untidy...
Is there some bit of magic tucked away that provides an easy mechanism to automatically start services as other, non-root users?
EDIT: I should have said that the processes I'm starting in this instance are either Python scripts or Java programs. I'd rather not write a native wrapper around them, so unfortunately I'm unable to call setuid() as Black suggests.
If you intend to write your own daemon, then I recommend calling setuid(). This way, your process can
Just to add some other things to watch out for:
Some things to watch out for:
I generally use /sbin/su to switch to the appropriate user before starting daemons.
Why not try the following in the init script:
It worked for me.
I needed to run a Spring .jar application as a service, and found a simple way to run this as a specific user:
I changed the owner and group of my jar file to the user I wanted to run as. Then symlinked this jar in init.d and started the service.
So:
on a CENTOS (Red Hat) virtual machine for svn server: edited
/etc/init.d/svnserver
to change the pid to something that svn can write:and added option
--user=svn
:The original pidfile was
/var/run/svnserve.pid
. The daemon did not start becaseu only root could write there.