How to make ubuntu service run as specific user?

I created an init.d script and make it start at boot, but sooner I found the service is running as root after reboot.

I google and google, people suggest run as a seperate user, so what's the steps?

  • 1
    You should specify for what Ubuntu you want this. Not all Ubuntu have upstart v1.4 so I will assume 12.04, 12.10 or 13.04. – Rinzwind Apr 24 '13 at 9:58
up vote 5 down vote accepted

Upstart v1.4+ states ...

setuid $user

Changes to the user before running the job's process.

  • Change $user to an actual username
  • Note that all processes (pre-start, post-stop, et cetera) will be run as the user specified.
  • Note that if you specify an invalid username in the setuid stanza, Upstart will log an error if it is in Debug Mode.
  • The documentation for this is huge and hideously complex. What are the simple steps to configure this? Edit a file somewhere? How to edit such file? Thanks. – InteXX May 24 '16 at 20:49
  • 1
    1. It is not simple and it is different across different Ubuntu's... 16.04 dropped upstart and uses systemd so most of us do not even use it anymore ;-) 2. depends on the procedure. In general you edit the file in /etc/init.d/ for the procedure you want to edit. The current files there should give some info on how to do this 3. vim, nano, gedit. – Rinzwind May 25 '16 at 6:40
  • I've been reading about the systemd issue and the fork. It seems there's been a bit of a row over the thing. Myself I'm not partial—if I can accomplish what I need, then I'm happy. This is a friend's older laptop anyway... I'll just wipe it clean and put the latest Lubuntu on it, which as you point out comes with systemd by default. Problem solved. So thank you for the brief education :-) – InteXX May 25 '16 at 18:10

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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