How to run app as root?

Discussion in 'OS X El Capitan (10.11)' started by FocusAndEarnIt, Oct 27, 2015.

  1. FocusAndEarnIt, Oct 27, 2015
    Last edited: Oct 27, 2015

    FocusAndEarnIt macrumors 601

    FocusAndEarnIt

    Joined:
    May 29, 2005
    #1
    Need some help.

    I need to make it so that if an app launches upon login, it runs as root. Currently, the app in question launches as a login item but runs as that user (standard account, not administrator). The app can be shutdown, even though its running in the background, by opening Activity Monitor and quitting the process--and I don't want this to happen. If, however, the app ran as root, it would require an admin password to shut down the process. Since the user doesn't have admin privileges, it couldn't be done.

    Thoughts? Help?
     
  2. NoBoMac macrumors 6502a

    Joined:
    Jul 1, 2014
    #2
    Try making a LaunchAgent/LaunchDaemon. If you go to /Library, you will see those folders. And should be examples of how some services get started at machine boot.

    Also can see examples of how to put one together at /System/Library.
     
  3. KALLT macrumors 601

    Joined:
    Sep 23, 2008
    #3
    A launch agent would probably be a good choice. It will run under a per-user launchd session. I am not sure, however, how you can get it to run under your son's user account only and prevent it from stopping without administrative privileges. You may have to look into this a bit more. Putting a protected file under ~/Library/LaunchAgents might do the trick, but I don't know how it affects the process that is launched.

    However, it is probably a better solution than a launch daemon and definitely a better solution that giving root access to a third-party application. That is just a recipe for trouble.
     
  4. chrfr macrumors 603

    Joined:
    Jul 11, 2009
    #4
    LaunchAgents run processes as the logged in user, not root. If they are in /Library, they run for every GUI user, while LaunchAgents in the home folder run for one specific user. The process always runs as the logged in user, regardless of where the LaunchAgent is. Processes which need to run as root need to be LaunchDaemons.
     
  5. chrfr, Oct 27, 2015
    Last edited: Oct 27, 2015

    chrfr macrumors 603

    Joined:
    Jul 11, 2009
    #5
    Exactly what application is it?
    I should add that what you're trying to do is non-trivial. In general, it's not possible to run an application that has a GUI as a different user (even root) inside another user's environment. It's a big security vulnerability to allow it.
     
  6. FocusAndEarnIt thread starter macrumors 601

    FocusAndEarnIt

    Joined:
    May 29, 2005

Share This Page