Forcing a GUI application to run as root

2019-08-17 23:46发布

I'm getting ready to deploy an app on OS X. This is the first time I've written an application on this platform which requires root permissions to run properly, so I need that functionality integrated for every startup attempt.

The application itself is written in Python 2.7, and then compiled to binary using PyInstaller. So far, I've tried:

  • Running PyInstaller using sudo pyinstaller -w --icon=/path/to/icon /path/to/script.py

  • Invoking the PyInstaller command using sudo su

I don't know what else to try at this point. Is it something that could be achieved using symlinks?

2条回答
乱世女痞
2楼-- · 2019-08-18 00:03

Running the installer as root will have no effect when you later start the application itself as a normal user.

Try sudo python /path/to/script.py instead.

If that works, then put this into a shell script and run that to start the app as root from now on (and the people who know MacOS can probably tell you how you can create a nice icon for the script).

WARNING Doing this makes your system vulnerable to attacks. If you do this on your own Mac, that's fine. If you're developing a product that you're selling to other people, then you need to revisit your design since it's severely broken.

查看更多
成全新的幸福
3楼-- · 2019-08-18 00:14

Apple recommend that no GUI applications run as root, as the libraries that are included in such applications increase the attack vector for malware.

Instead, it is recommended to refactor your code into two parts, the Gui and a separate helper app, which is given root privileges.

There's an example application here.

查看更多
登录 后发表回答