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

From Qt Wiki
Jump to navigation Jump to search
(Add "cleanup" tag)
(Layout)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
{{LangSwitch}}
 
[[Category:HowTo]]
[[Category:HowTo]]
[[Category:Tutorial]]
[toc align_right="yes" depth="2"]
= How to Get Application Running with Root Privileges =


== Introduction ==
== Introduction ==
Line 12: Line 6:
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.
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":http://fedoraproject.org/, but should work on any other "Red Hat":http://www.redhat.com/ based distributions.
'''Note:''' This steps has been only tested on [http://fedoraproject.org/ Fedora GNU/Linux], but should work on any other [http://www.redhat.com/ Red Hat] based distributions.


== Installing the usermode package ==
== Installing the usermode package ==
Line 20: Line 14:
To install this package just execute the following command:
To install this package just execute the following command:


'''yum install usermode'''
<pre>
yum install usermode
</pre>


== The /etc/security/console.apps/ directory ==
== The /etc/security/console.apps/ directory ==
Line 26: Line 22:
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:


<pre>
/etc/security/console.apps/myapp
/etc/security/console.apps/myapp
</pre>


…and the contents:
and the contents:


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


== The /etc/pam.d/ directory ==
== The /etc/pam.d/ directory ==
Line 38: Line 38:
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:


File
<pre>
/etc/pam.d/myapp
/etc/pam.d/myapp
</pre>
Content:


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


== Linking ==
== Linking ==
Line 49: Line 57:
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:


<pre>
ln -fs /usr/bin/consolehelper /usr/bin/myapp
ln -fs /usr/bin/consolehelper /usr/bin/myapp
</pre>


'''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.
Line 59: Line 69:
This .desktop file could look like this:
This .desktop file could look like this:


<code>[Desktop Entry]
<pre>
[Desktop Entry]
Categories=System
Categories=System
Exec=/usr/bin/myapp
Exec=/usr/bin/myapp
Line 70: Line 81:
Terminal=false
Terminal=false
Type=Application
Type=Application
</pre>

Latest revision as of 22:08, 21 August 2016

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

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, but should work on any other Red Hat 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
PROGRAM=/usr/sbin/myapp
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:

File

/etc/pam.d/myapp

Content:

#%PAM-1.0
auth include config-util
account include config-util
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