How to get applications running with root privileges: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=How to Get Application Running with Root Privileges=
[[Category:HowTo]]<br />[[Category:Tutorial]]


==Introduction==
[toc align_right=&quot;yes&amp;quot; depth=&quot;2&amp;quot;]


This tutorial is intended for developers with the need for their applications to run with root privileges, without using '''su''' or one of it <span class="caps">GUI</span> 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.
= How to Get Application Running with Root Privileges =


'''Note:''' This steps has been only tested on [http://fedoraproject.org/ Fedora <span class="caps">GNU</span>/Linux] ''[fedoraproject.org]'', but should work on any other [http://www.redhat.com/ Red Hat] ''[redhat.com]'' based distributions.
== Introduction ==


==Installing the usermode package==
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 &quot;Fedora GNU/Linux&amp;quot;:http://fedoraproject.org/, but should work on any other &quot;Red Hat&amp;quot;:http://www.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.
The '''usermode''' package contains the '''userhelper''' program, which can be used to allow configured programs to be run with superuser privileges by ordinary users.
Line 15: Line 19:
'''yum install usermode'''
'''yum install usermode'''


==The /etc/security/console.apps/ directory==
== 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:
This directory have to contain a file with the same name (has to be lowercase) of our application binary and without extention, for example:
Line 23: Line 27:
…and the contents:
…and the contents:


==The /etc/pam.d/ directory==
<code>USER=root<br />PROGRAM=/usr/sbin/myapp<br />SESSION=true</code>
 
== 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:
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:
Line 29: Line 35:
/etc/pam.d/myapp
/etc/pam.d/myapp


==Linking==
<code>#%PAM-1.0<br />auth include config-util<br />account include config-util<br />session include config-util</code>
 
== 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:
Now we have to create a symlink with the name (has to be lowercase) of our application binary and linked to the consolehelper program:
Line 37: Line 45:
'''Note:''' The real binary of our application have to be placed at /usr/sbin/ directory.
'''Note:''' The real binary of our application have to be placed at /usr/sbin/ directory.


==The .desktop file==
== 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.
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.
Line 43: Line 51:
This .desktop file could look like this:
This .desktop file could look like this:


===Categories:===
<code>[Desktop Entry]<br />Categories=System<br />Exec=/usr/bin/myapp<br />GenericName[en_US]=My App<br />GenericName=My App<br />Icon=myapp<br />Name[en_US]=MyApp<br />Name=MyApp<br />StartupNotify=true<br />Terminal=false<br />Type=Application
 
* [[:Category:HowTo|HowTo]]
* [[:Category:Tutorial|Tutorial]]

Revision as of 09:34, 24 February 2015


[toc align_right="yes&quot; depth="2&quot;]

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&quot;:http://fedoraproject.org/, but should work on any other "Red Hat&quot;:http://www.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:

USER=root<br />PROGRAM=/usr/sbin/myapp<br />SESSION=true

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

#%PAM-1.0<br />auth include config-util<br />account include config-util<br />session include config-util

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:

[Desktop Entry]
Categories=System
Exec=/usr/bin/myapp
GenericName[en_US]=My App
GenericName=My App
Icon=myapp
Name[en_US]=MyApp
Name=MyApp
StartupNotify=true
Terminal=false
Type=Application