How to get applications running with root privileges

From Qt Wiki
Revision as of 15:46, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

How to Get Application Running with Root Privileges

Introduction

This tutorial is intended for developers with the need for their applications to run with root privileges, without using su or one of it GUI equivalents, like kdesu. The steps shown below are not directly related to Qt, indeed with the operative system, so the developer has to have a basic of system administration knowledge. However this five steps are very easy, so there should be no problem to accomplish it. When we have done all this, an authentication dialog will show up just before our aplication to run, after typing the correct root password we are going to have our application running with administrator rights.

Note: This steps has been only tested on Fedora GNU/Linux [fedoraproject.org], but should work on any other Red Hat [redhat.com] based distributions.

Installing the usermode package

The usermode package contains the userhelper program, which can be used to allow configured programs to be run with superuser privileges by ordinary users.

To install this package just execute the following command:

yum install usermode

The /etc/security/console.apps/ directory

This directory have to contain a file with the same name (has to be lowercase) of our application binary and without extention, for example:

/etc/security/console.apps/myapp

…and the contents:

The /etc/pam.d/ directory

This directory also have to contain a file with the same name (has to be lowercase) of our application binary, without extention and with the following content:

/etc/pam.d/myapp

Linking

Now we have to create a symlink with the name (has to be lowercase) of our application binary and linked to the consolehelper program:

ln -fs /usr/bin/consolehelper /usr/bin/myapp

Note: The real binary of our application have to be placed at /usr/sbin/ directory.

The .desktop file

The last is concerned with the .desktop file of our application, that have to point to the link we create in the previous step insted of the real binay.

This .desktop file could look like this:

Categories: