Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm porting a Debian init.d script to CentOS. In the Debian script, it uses start-stop-daemon for launching the process. The script uses start-stop-daemon's --group flag to change to a different group-id when starting the daemon process.

How do I set the group-id of the daemon process in the init script on CentOS?

share|improve this question
up vote 2 down vote accepted

CentOS init scripts use /etc/init.d/functions, which declares a "daemon" function that most other init scripts use. But daemon doesn't accept any group flags.

It ends up calling:

$nice runuser -s /bin/bash - $user -c "$corelimit >/dev/null 2>&1 ; $*"

A quick /sbin/runuser --help shows that runuser accepts a flag to specify group, so try:

runuser -g $group; daemon ...
share|improve this answer

If CentOS doesn't provide any better way (which would surprise me a little), you can fall back on su's lesser known counterpart, sg:

sg foogroup -c 'exec foodaemon --bar'
share|improve this answer
It would surprise me as well! I was hoping someone with more experience with CentOS than I would chime in. – Lorin Hochstein Oct 22 '10 at 2:58

There is setuidgid: "setuidgid runs another program under a specified account's uid and gid."

It is part of daemontools, however, it probably is not available in the CentOS repositories due to DJBs strange licenses. So you might have to find a RPM (e.g. here) or build from source.

share|improve this answer

Very old question but I think I can add a few cents:

You can simply pay with the intrinsically flawed way daemon calls /sbin/runuser and set you username to something like:

echo -n "Starting ${prog}"
daemon --user='nobody -Gnogroup' $exec &

And it will work.

It is particularly dirty but allows you to piggyback on daemon without having to call runuser directly (or twice).

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.