Give me an example and I'll try and help you out. Red Hat does this with all of it's graphical administrative tools. You click on an admin tool and it will pop up with a root password box before it runs, and when it does run it runs as root.
It does this with a program called "consolehelper" which is part of the "usermode" package. I believe this package was written by the Red Hat guys but I also believe it to be a fairly standard package on most every Linux distro. It is very easy to add an application that you need to run under root.
$
man consolehelper
Say you want to start a konqueror file manager as root from your normal user desktop and you want to be able to just add it as a menu item or ICON on your desktop. What I do is first create link in /usr/bin to consolehelper with the name I want to use to start the program (konqueror-root might be a good name):
$ su -
# cd /usr/bin
# ln -s consolehelper konqueror-root
Now I create a text file called /etc/security/console.apps/konqueror-root that contains this:
- Code: Select all
USER=root
PROGRAM=/usr/bin/konqueror
SESSION=true
I'm not sure if this "/etc/security/console.apps" directory is the same on all distros, I would guess not. Also, look at the other files in that directory and make sure they are set up similar to my example above. The last thing I need to do is create a /etc/pam.d/konqueror-root:
- Code: Select all
#%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
Actually if you look in /etc/pam.d you might see the names of other programs in there. You can just copy one of them to the name of your program in the same directory.
Now if everything goes right at a shell prompt you can type:
$ konqueror-root
and it will pop up with a graphical password box asking for root's password. If you type it in properly it should bring konqueror up running under root's ID and in root's home directory. If all works then add "/usr/bin/konqueror-root" to your menu or desktop ICON. When you click it it should prompt you for root's password.
Just follow the same example for any program you want to run as root from a desktop icon without giving up too much security. It's better to give up a little security here and there and only when you need it rather than just throwing your hands up and saying there's no point in even trying.
Now, when you absolutely have to run a command as root from another ID without a password, or for allowing other users who do not have root access to be able to run selected programs as root, then "sudo" is the proper command. But I always at least try to find another solution first and use "sudo" as a last resort. In fact I try and set things up so I don't have to "su" all that much period. The fewer things that need root access the better. Good file system security is also very important.
And of course you can run any command directly at a shell prompt without any configuring necessary as root just by using "su":
$ su - -c "konqueror"