9

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??

Coldsteel48
  • 3,482
  • 4
  • 26
  • 43

3 Answers3

4

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.

Ivan X
  • 2,165
  • 16
  • 25
  • And I can upload it to appStore with this ? – Coldsteel48 Jun 06 '14 at 18:26
  • Definitely not. You'd need to programmatically grant privileged access via appropriate frameworks, and even then I don't even know one way or the other if they let anything at all that uses privileged access into the Mac App Store. I'm thinking they don't but can't say so authoritatively. – Ivan X Jun 06 '14 at 23:03
  • can you explain in detail regarding AppleScript as you wrote above i write as you suggested above under BUILD PHASES-> RUN SCRIPT .. but it is giving me errors. – Malav Soni Mar 31 '15 at 12:00
3

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.

ian
  • 12,003
  • 9
  • 51
  • 107
  • Indeed. The correct way to do this is request authorization for specific tasks or to log in as root. There is no reason any user land app should run with root privileges constantly. That just gives the user root and opens things for disaster. Both external and user blunder. – uchuugaka Jun 03 '14 at 06:53
  • It looks like exactly what I want , just didn't understand about tasks: when I call a method : I can put it there on vompletion block , and then run my restricted function ? – Coldsteel48 Jun 03 '14 at 07:40
  • i am using this https://github.com/halo/macosvpn code in osx Application, this code work only when i set root and compile from Xcode, but when i run myapplication.app file not working, not store password in System Keychain. Furthermore i have install Helpertool, still no progress – Sawan Cool Sep 09 '15 at 14:58
  • i have install helperTool successfully, still macosxvpn socurce code not store password in System Keychain on Debug Process as (Me). Can anyone help me? – Sawan Cool Sep 10 '15 at 06:30
  • @SawanCool You seem to be lost. Please ask a new question. –  Sep 10 '15 at 07:02
  • Is it possible to run the privileged operations as root without need of manual re-authorizing/authenticating (after the first time). I have a small bash script that need's to run under root, but using `sudo` I have to re-type password almost every time it's run. Is there something like _permanent sudo_ in Authorization Services? – Petr Peller Nov 21 '15 at 09:58
  • 4
    sometimes developers like me needs to execute some apps with `sudo` so don't tell such things like `mac os x is not intended to be used in that way`... osx is unix bases OS and its normal to use `root` permissions sometimes. see also (AppleSupport)[https://support.apple.com/en-us/HT204012] – To Kra Jan 27 '16 at 10:02
  • @ToKra As you said yourself, it's normal to use root privileges **sometimes** - *e.g,* by using Authorization Services to run specific operations as root. It is not normal to run an entire desktop application as root all the time. –  Jan 27 '16 at 12:03
1

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

Feng Liu
  • 954
  • 13
  • 22