How do I give root privileges to an app?
I tried to submit an app to the Ubuntu Software Centre but it was rejected because you needed to put in the admin password to use it. I need to grant root privileges to the app for it to function so I used sudo. But they said I can't use sudo in my app. How can I give it root privileges?
Solution 1:
You need to use the PolicyKit
APIs to request the escalation of privileges. In general, you should only do so when it's absolutely necessary, and not run the application with escalated privileges at all times.
It's worth noting that if you only need root privileges on startup, you can and should start up as root, but then drop to an unprivileged user. If you're operating as a user-facing program, this probably means the user that ran the program; if this means a daemon, like an httpd
or sshd
, it probably means an incredibly locked-down user that's created specifically for your program to run under.
Also, there are graphical frontends to sudo
called gksudo
and kdsudo
for GNOME and KDE, respectively. If someone recommends that you use these, don't. Be aware that these programs are deprecated in favor of PolicyKit
, are not installed by default, and will probably get your app rejected.
Solution 2:
Your app might not be permitted at all. According to the Ubuntu wiki, the App Review Board will reject applications that touch system files:
Your application appears to touch system files as part of its operation, however we do not allow apps to do this as part of a security policy for extras.ubuntu.com. For these applications, we recommend that you follow the steps on https://wiki.ubuntu.com/UbuntuDevelopment/NewPackages for submitting your package to Debian or Ubuntu.
A cleanup app would be touching system files.
While this guideline only applies to open-source apps (the policy for proprietary apps is not published), I imagine similar rules apply to proprietary apps.
If your app is open-source, you can still get it into the Software Center by packaging it and submitting it to the main Ubuntu or Debian repositories.
Solution 3:
You don't need PolicyKit or any of that. Just change the apps owner and permission level:
sudo chown root:root /path/to/app
sudo chmod 4755 /path/to/app
Of course, you will need root privileges in order to execute these commands.