How to make your app run as root?

asked 2015-09-20 16:52:30 +0300

Rikudou_Sennin gravatar image

updated 2015-09-20 16:57:30 +0300

Hello, I am trying to make an app that will start as root user, but I am not really experienced in C++.

My binary has a sticky UID 0 and in the code setuid(0).

And what really confuses me is that when I start the app from terminal (as nemo user) it has root privileges but when I start via desktop file, it runs as nemo user.

Can anybody help me with it?

edit retag flag offensive close delete


You really shouldn't make your app run as root. I think it's better to do a privileged DBus daemon running as root and then an un-privileged application that interfaces with it.

Regarding your problem, do you use invoker in your desktop file? Maybe that's the issue.

g7 ( 2015-09-20 18:27:02 +0300 )edit

Hello, I don't use invoker, how should I use it?

Rikudou_Sennin ( 2015-09-20 18:57:22 +0300 )edit

Ah, found it, thank you very much for pointing the way :) Can you please send some resources about using the DBus method?

Rikudou_Sennin ( 2015-09-20 19:04:36 +0300 )edit

DBus is pretty common in desktop Linux distributions, you'll find plenty of resources online. I never used the C++ bindings (nor the one provided by Qt) but this seems a good place to start:

I have written an application for SailfishOS with a DBus service, written in vala: Maybe that's useful.

To interface with the service from the QML application, you can import org.nemomobile.dbus and use the DBusInterface object.

Ideally you should use Polkit to manage authentication but I don't know if there is a proper SailfishOS frontend for it (I remember that it was in the works before).

g7 ( 2015-09-20 20:31:08 +0300 )edit