Coldsteel48
Coldsteel48

Reputation: 3512

How to set my application to always run as root OSX

I am developing an OSX application that some features of it requires ROOT privileges I figured out how to debug my app as root (simply in schemes).

But I want users to run it as Root so they will have access to its features.

How can I do this??

Upvotes: 9

Views: 27376

Answers (3)

Feng Liu
Feng Liu

Reputation: 1012

You can create a local server and keep it running in /Library/LaunchDaemons. This will let the server auto startup and gain the root privilege. I found a good article talking about this.

https://medium.com/@fahimhossain_16989/adding-startup-scripts-to-launch-daemon-on-mac-os-x-sierra-10-12-6-7e0318c74de1

Upvotes: 1

user149341
user149341

Reputation:

Do not run desktop applications as root. The Mac OS X frameworks are not intended to be used this way, and undesirable behavior will result (e.g, files/folders owned by root in the user's Library; process not responsive to "force quit"; potential security vulnerabilities).

Use Authorization Services to run specific, limited privileged operations as root.

Upvotes: 3

Ivan X
Ivan X

Reputation: 2195

If it's a typical OS X application bundle, you can run it as root in the Terminal with:

sudo /Applications/YourAppName.app/Contents/MacOS/YourAppName

You could save a file containing just this, and name it YourAppLauncher.command, and it would be double-clickable from the Finder.

Or, in AppleScript:

do shell script "/Applications/YourAppName.app/Contents/MacOS/YourAppName" ¬
    with administrator privileges user name "username" password "password"

Then save that as an Application to launch your app as root. It won't prompt for a password (if you want it to, remove everything after with administrator privileges.

Upvotes: 5

Related Questions