Ubuntu – How to give root privileges to an app

application-developmentapplication-submissionrootsudo

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?

Best Answer

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.

Related Question