Custom Launcher to Run Graphical Commands as Root in Ubuntu
LINUX UPGRADES AND UPDATES
CUSTOM APPLICATION LAUNCHER RUNNING GUI AS ROOT
ometimes it's handy to have a utility when you run GUI programs that require root privileges (e.g. the network configuration applet). Linux-law is to "Know Thy Terminal" commands, but if I can deploy something else that keeps me from having to slow down to do so? I know, six-and-one-half-dozen of the other here (but seriously, typing into terminal is a waste of time = FACT). But, should you have the need for this type of thing (or, just want one), here's the How-To on it by speaking out of both sides of my mouth for Ubuntu and RHEL.
While sudo is our go-to for safer root priv executions, you should never use normal sudo to start graphical applications as Root. If you've ever done this, whether mistakenly or purposefully, you've learned the hard way why not to! Instead, use gksudo, a frontend to sudo (that simply links to the gksu command). Gksudo's primary purpose is to run graphical commands that need root without the need to run an X terminal emulator and using su directly; this obviously prevents files in your home directory becoming owned by Root. I'm not going to service the pros and cons argument here for doing this in the first place, nor am i going to enjoin the banter for pkexec versus what is now the admittedly deprecated gksudo. My Ubuntu system (14.014 LTS) already has gksudo, so I'm going to use it for my purposes here; this is just as easy to accomplish in RHEL (6.5) - those options are further provided, below; ENJOY!
SumoSudo Application Launcher in Ubuntu
Our goal here is to make a custom application launcher that runs gksudo, allowing us to then execute GUI applications with root privileges. That's some #sumosudo! To create this launcher in Ubuntu with Unity desktop, we have to set this up manually. Grab yourself a licensed-to-use .png icon for your launcher (or simply make one of your own) - the launcher icon needs to be porportionate across x-y axis (128x128 seems to work nicely for me, named in my example "sumosudo.png").
To get the icon image in a proper directory, we need to open Nautilus with elevated privileges (something our new custom launcher intends to help us do going forward):
$ sudo nautilus
browse to: >computer >user >share >icons and drag & drop/cut & paste your new icon there (or to any other logical permanent directory where you can easily drill down on it)
Let's find the application we need (gksudo) for our new launcher - this should be found located under /usr/bin/ - just remember this location for now as we will need it later in creating our launcher...
Now create a working desktop file by opening gedit with elevated privileges and encode the below text into the new file:
$ sudo gedit
Encode the new file with the following lines:
- [Desktop Entry]
- Name=YourNewApplicationName [enter a name for your new application launcher; in this example mine is "SumoSudo"]
- Comment=Utility for Running Applications as Root [enter a descriptive comment as to what the launcher is for/does]
- Exec=/usr/bin/gksudo [enter the location from earlier where we found our gksudo application]
- Icon=/usr/share/icons/sumosudo.png [enter the location and name of your icon for this application launcher; in this example mine is "sumosudo.png"]
- Terminal=false [specifies whether the application should run in a terminal window or not; set to "false", as this is not a Terminal application]
- Type=Application [specifies the type of the launcher file; this will be an "Application"]
- Categories=Developer [the category you would like to designate the launcher for Unity filtering - categorize any way you prefer, multiple categories are acceptable - separate Categories by semi-colon for multiples]
Save this file named as "yourapplicationname.desktop" (in my example, "sumosudo.desktop") and to directory: usr/share/applications. Your saved .desktop file should look as follows:
Test and make sure our new application launcher is there, is accessible and is functioning as expected: search for it, open it and in my case I add this to the Unity Launcher for easier access. In order to add your launcher to the Unity Launcher on the left, you select and drag it onto the Launcher panel. Here's my new SumoSudo launcher!
Running the application now from the Unity Launcher by dbl-clicking our application icon results in:
Now you can simply type the application you want to run under gksudo!
Applications Launcher Under Root in RHEL
The complimentary approach to what we've done above in Ubuntu is accomplishable in RHEL via BEESU, a graphical wrapper for su in Fedora-based distros. Install via PackageKit and configure beesu to your own liking; it comes with some handy scripts for Nautilus and plugins for gEdit.