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

Is there a way to have an application launch during startup under a certain user account?

For example, I would like to have a_small_app run under the user account bob (which is in the group bobsgroup). Do I add something to /etc/init.d?

Note: I don't want the application to start after a user logs in but rather when the computer starts.

share|improve this question
Do you want the app to start before login in the login window? – Martin Owens -doctormo- Jan 5 '11 at 22:55
@Martin: Well, it doesn't really matter... I'm using Apache as an example here. When does it start? – Nathan Osman Jan 5 '11 at 23:10
up vote 8 down vote accepted

A startup system agnostic method. You can use this in /etc/rc.local, a /etc/init.d/... script, an Upstart configuration file and probably a systemd configuration too.

sudo -u oli /full/path/to/application

This command will run as the root user and sudo will drop down to the "oli" user. Obviously change the user and the command for your purposes.

I should add that there are at least a dozen ways of doing just this... But in my experience they're all largely identical in effect. Here's an upstart example using its setuid stanza:

start on (filesystem and stopped udevtrigger)
stop on runlevel [06]

setuid oli

exec /full/path/to/application
share|improve this answer
I suggest that the example – waltinator Sep 28 '11 at 22:15
I get sudo: unknown group: 1004 – ThorSummoner Sep 4 '14 at 5:01
Also, poke: Time to update line about upstart. – muru Jan 19 '15 at 11:16
@muru I will. But group isn't required. sudo will use the specified user's default group. – Oli Jan 19 '15 at 12:08
Better edit it out, then. That command's been wrong for three years since somebody improved it! :D – muru Jan 19 '15 at 12:10

It seems that the first answer doesn't work in Ubuntu 14.10 anymore.

This is how I do it there (put it in /etc/rc.local)

su <username> - -c <command>
share|improve this answer
If you need a login shell, the equivalent is sudo -i -u .... – muru Jan 19 '15 at 11:11

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.