Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 have a init.d script that start|stops|restarts a daemon using the start-stop-daemon.

This daemon is always started as root. I want to be able to specify the user that the init.d script will use to start the daemon.

Tried using the --user option for start-stop-daemon but that is not working.

Can someone please suggest how to do this.

share|improve this question
You might want look at /etc/init.d/functions: the daemon function already allows you to set an alternate user: daemon --user=my_user my_cmd &>/dev/null & This is implemented by wrapping the process invocation with runuser - more on this later. – VendettaDroid Sep 8 '12 at 9:30
Acutally i have a init.d script. it calles the start-stop-daemon which also allows me to set the user and group, which I am doing. For some reason this is not working though. – kapad Sep 8 '12 at 12:12
up vote 0 down vote accepted

As Ubuntu is converting away from sysvinit to upstart, I'd suggest that you convert your script to an upstart job in the /etc/init/ directory instead. The man page is man 5 init.

There are setuid and setgid items to set the user and group under which the upstart job is run.

Assuming your script execs another script, I suppose you can add the su userid command to it to change the effective uid and gid to that of its argument. I'm uncertain whether its safe to run su in the sysvinit script itself without it changing these for subsequent /etc/init.d/ scripts, but perhaps that's OK, too.

share|improve this answer
Thanks. I'll try this. But do you know how to do this for an init.d script. I already have that script ready and I need to make this change ASAP. – kapad Sep 9 '12 at 14:12
Added another idea, don't know if its feasible. – John S Gruber Sep 9 '12 at 14:43
Ya. Ill try the second one now. The first one didn't work for some reason. I saw the man pages for start-stop-daemon and it should work according to those pages, but didn't. – kapad Sep 28 '12 at 9:30

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.