I want to run a command on startup on my Ubuntu Server. Does anyone know how to do this? Does /etc/rc.local run as superuser? Any help will be appreciated. Thanks!


2 Answers 2


/etc/rc.local will run as root.

Most of the init process is run as root, or starts out that way.


There's a couple of places you can do this:

/etc/init.d (and then making a link to /etc/rc[runlevel].d - usually 2) works pretty well - so you can specify start up and shut down bits in there.

That's kind of an old way (though oh so very easy). You can also do something with upstart. Look at this page (look at the "Writing Jobs" section).

The big gotcha - the path is normally not quite what you'd expect. So I'd suggest running something along the lines of "echo $PATH > /init_path" from whatever script first to see if you might have an issue (check /init_path and see what's in there.. perfectly safe to remove this file). While it's easy to specify paths in your script, it's worth setting the PATH variable accordingly as anything run from whatever script may also need things in PATH.

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