How to launch application as root from Unity Launcher?

Mainly I am looking for a way to pin an application to the Unity launch bar, and run it as root.

Currently, even if I start the application with sudo, and pin it after it starts, it will start as current user next time.

Sad, but there is no context menu option "run as ...".

Update: I switched to gnome3 and now I'm happy, I'm missing only the search.


If you want the app to always run as root

  1. Pin the application to the launcher as normal.

  2. Locate the applications .desktop file which will be in either:

    • /usr/share/applications/APPNAME.desktop
    • ~/.local/share/applications/APPNAME.desktop
    • or somewhere else, use locate .desktop|grep APPAME
  3. Open with gedit:

    gksudo gedit /usr/share/applications/APPNAME.desktop
    
  4. Then change the line

    Exec=APP_COMMAND
    

    to

    Exec=gksudo -k -u root APP_COMMAND
    
  5. Save

This command will also keep your environment which is very usefull if you need to connect to others servers and use your private key.

To add a quicklist option to 'Run as root'

Follow steps 1, 2 and 3 above

If the launcher currently doesn't have any other quicklist options, just append this to the end of the document

X-Ayatana-Desktop-Shortcuts=Runroot

[Runroot Shortcut Group]
Name=Run as root
Exec=gksudo -k -u root APP_COMMAND
TargetEnvironment=Unity

In the Main Menu under System, Preferences, type gksudo in the Command field of Launcher Properties, e.g.:

/usr/bin/gksudo /usr/bin/yourapplication

Your Name field might say:

sudo yourapplication

So users know they may see a password popup and why...

I am not sure about Unity Launcher vs Main Menu. Maybe this helps?

Good luck


As this is an old question, with an old answer; To complement @edm's amazing explanation.

As of Ubuntu 18.04 and later, gksudo (gksu) is deprecated and so, it does not have an install candidate in the official repositories. An alternative is to use pkexec.

Edit the file /usr/share/applications/APPNAME.desktop and change the line

Exec=APP_COMMAND

to

Exec=pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY APP_COMMAND

More details on pkexec here.


The following seems to do the same thing, without needing private attributes:

Actions=Runroot;Another

[Desktop Action Runroot]
Name=Run as root
Exec=gksudo -k -u root APP_COMMAND

[Desktop Action Another]
Name=Another action
Exec=whatever

As a quick and simple alternative to the cumbersome demands described in the answers here, I've gotten in the habit of doing the following...

  1. Launch a new terminal.
  2. Enter gksu nautilus

    (sudo -i nautilus works, too.)

The resulting window falls under the sudo umbrella, so you can use it to access and launch files with sudo-root privileges to your heart's content until it closes. This comes in handy for transitory situations where you don't need a more permanent solution. I use it routinely to extract compressed files into protected system folders, for instance.