Ask Your Question

Revision history [back]

The thing is that if you want to run as root a graphical application you have 2 ways:

1.- Open the terminal and type:

$ sudo app_name

or

2.- Add a policy kit rule:

In /usr/share/polkit-1/actions you have to create a xml file with the information about the application you want to run with privileges. In my case I wanted to run glogg cos I need to open system log files and had to be root for that.

After you create the xml file you have to edit the .desktop file in /usr/share/applications, adding before the binary name, the pkexec command.

That's all. Then you've got your application asking for root password.

For glogg I create this XML, named org.freedesktop.policykit.pkexec.glogg.policy (path: /usr/share/applications/)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>

    <vendor>Nicolas Bonnefon</vendor>
    <vendor_url>http://blog.bonnefon.org/</vendor_url>

    <action id="org.freedesktop.policykit.pkexec.glogg">
    <description>Run glogg with elevated privileges</description>
    <message>Authentication is required to run glogg as root</message>
    <defaults>
      <allow_any>auth_admin_keep</allow_any>
      <allow_inactive>auth_admin_keep</allow_inactive>
      <allow_active>auth_admin_keep</allow_active>
    </defaults>
    <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/glogg</annotate>
    <annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
  </action>

</policyconfig>

And the glogg.desktop file (path: /usr/share/applications):

[Desktop Entry]
Name=glogg
GenericName=Log file browser
# %f because glogg supports only one file for now
Exec=pkexec glogg %f
Icon=glogg
Type=Application
Comment=A smart interactive log explorer.
Terminal=false
Categories=Qt;Utility;TextTools;Development;
MimeType=text/plain;
Actions=Session;NewInstance;

[Desktop Action Session]
Exec=pkexec glogg --load-session %f
Name=Open With Previous Session

[Desktop Action NewInstance]
Exec=pkexec glogg --multi %f
Name=Open In A New glogg Window