Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

FocusAndEarnIt

macrumors 601
Original poster
May 29, 2005
4,628
1,112
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?
 
Last edited:

NoBoMac

Moderator
Staff member
Jul 1, 2014
6,289
4,986
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.
 

KALLT

macrumors 603
Sep 23, 2008
5,380
3,415
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.
 

chrfr

macrumors G5
Jul 11, 2009
13,709
7,280
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.
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.
 

chrfr

macrumors G5
Jul 11, 2009
13,709
7,280
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).
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.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.