Google Site SearchFN Site Search FN Blog Login FN Blog Login
Site Navigation:
 
 

How to run a program from GNOME menu with root privileges

by Matt Hansen on Feb 9, 2004 (UPDATED Apr 15, 2004)

Thanks to some great input and suggestions from David L. Norris, I have updated this document to reflect his superior solution. It eliminates the need to alter /usr/bin/nautilus and modify your PATH by making a separate filename specifically for a root-privileged nautilus. He has also written a handy shell script to automate the process entirely. It can be found here.

Warning:
Take note that running programs with root privileges can be potentially dangerous as there is no protection for the user. Take due care and always understand what you are doing before messing with important files and remember to back up!

Most of the programs one would use that require root privileges in the GNOME menu tree have already been set up as part of the standard Fedora desktop installation. However, there may be some you add or even ones there that you would benefit from having the ability to run as root. One of these, and the one I will use as my example is nautilus the standard GNOME GUI file manager.

There are at least a couple ways to do this. The first is a simple, command-line method of running a program with root privileges (from a normal user account). The second is a GUI-based approach to the process and is used for all the standard programs that need to be run as root (such as all those in /sbin, /usr/sbin, etc.). It is the focus of this tutorial.
  1. If you have set up your sudoers file and have a working sudo command (recommended), then simply issuing a `sudo<program-name>` from a terminal will allow you to run the program with root privileges. NOTE: See Thomas Chung's article "How to create rpmbuild directory" to see how to set up sudo if you haven't already. In our example, you would use `sudo nautilus`, enter the root password and nautilus will open up in /root with full access to all files/folders.
  2. The method in our tutorial uses the program /usr/bin/consolehelper which is the little pop-up box run for any of the programs in the menu requiring root permissions (such as System Tools -> System Logs). It allows you to simply enter your root password into the box and the program launches as root. It is simply a GUI wrapper to the program /usr/bin/userhelper which uses `pam_console` behind the scenes to do the real work.

Now let's run through how you would accomplish this.

First we need to create a symlink from nautilus-super, as we shall call it, to consolehelper:
$cd /usr/bin
$sudo ln -s consolehelper nautilus-super
This will be the program name we run to grant root priviliges to nautilus. Next, the PAM configuration files must be created so that nautilus can authenticate properly:
$sudo gedit /etc/pam.d/nautilus-super
Enter the following and save:
#%PAM-1.0
auth sufficient pam_rootok.so
auth sufficient pam_timestamp.so
auth required pam_stack.so service=system-auth
session required pam_permit.so
session optional pam_xauth.so
session optional pam_timestamp.so
account required pam_permit.so
$sudo gedit /etc/security/console.apps/nautilus-super
Enter the following and save:
USER=root
PROGRAM=/usr/bin/nautilus
SESSION=true
Now, running "nautilus-super" from a terminal will prompt for your root password:

consolehelper for nautilus

One final thing you may wish to do is add a menu entry for this superuser nautilus. To do this, copy the menu entry for "Home Folder" to a new file and open it for editing:

$cd /usr/share/applications
$sudo cp -a gnome-nautilus.desktop gnome-nautilus-super.desktop
$sudo gedit /usr/share/applications/gnome-nautilus-super.desktop
Change the relevant variables in the file to the following and save:
Name=Home Folder (Super User)
Comment=View all files on the system with a Super User Nautilus.
Exec=nautilus-super
Categories=Gnome;Application;System;Utility;X-Red-Hat-Base
You should now be able to select GNOME Menu-> System Tools -> Home Folder (Super User) and be prompted for root's password to launch a nautilus window with root access permissions.

GNOME menu item for nautilus-super