Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

What i am trying to do is design a script that will open an application, which i will then add as a login hook so when the user logs in, the login hook will run the script as root, which will then start the application as root. I have no scripting experience at all, and have tried some examples of other scripts, but to no avail at all. Any help would be much appreciated.

EDIT. I am running OS X 10.6.4

share|improve this question
What OS are you on? Ubuntu? If it is here you go - Ubuntu Start up – slotishtype Jun 2 '11 at 15:21
Out of curiosity, why does the application need to run as root? – Stephen Jennings Jun 3 '11 at 15:00
The application needs to be run as root to prevent the users from trying to kill the process. They can kill their own, but as root, they cant kill it. – Stiny861 Jun 15 '11 at 1:08

If's a graphical login, then link the application into ~root/Desktop/Autostart/. If it's a shell login, you can put commands in ~/.login and it'll get invoked. But this is generally dangerous to do and make sure you consider how the program will be stopped, what happens when the user (root) logs in more than once, etc.

share|improve this answer

You can make the shell script setuid (so it will always run as the owner of the file, which will be root), but this is a very dangerous thing to do. There are security implications for making shell scripts setuid.

The script would look something like this:

#!/bin/sh -
open /Applications/

Now make the script setuid from the Terminal:

sudo chown root
sudo chmod 4755

The first command makes root the owner of the file. The second sets it as setuid, read/write/execute by its owner, and read/execute by everyone else.

Then in Mac OS X, go to System Preferences → Accounts, and add the shell script as a login item for the user. Now each time the user logs on, the script will be called, and since it is setuid, it should run as root.

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.