Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
If you know the risk of running graphical apps as root and still want to continue then follow step 1 here: askubuntu.com/a/118483/41562 –  edm Apr 4 '12 at 10:31
    
You did not understand the question, I know how to use sudo and I already tunned it. The question is about how can I create a shortcut to Ubuntu Unity launcher to app that I want to run as root. –  sorin Apr 4 '12 at 11:40
    
For unity launcher, I don't know. But if you have a file residing on your desktop and you want to run it as gksu, then you can install "nautilus execute" extension. –  Curious Apprentice Mar 24 '13 at 10:28

5 Answers 5

up vote 27 down vote accepted

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) Change then 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
share|improve this answer
9  
Why is it so extremely complicated to set a simple Shortcut ? What wrong with the creators of ubuntu ? –  Panique Dec 13 '12 at 9:36
    
I did step 1-5 and application asks for password, but won't launch. –  user1880405 Aug 18 at 8:57

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

share|improve this answer
    
You probably know that straight sudo shouldn't be used to run graphical applications as root--after all, you are using gksudo (which is one of the good ways). For the same reason, it is inadvisable to use sudo in the name field the way you have, because doing so (1) creates the impression among sufficiently experienced users that your launcher is incorrectly made, and (2) creates the impression among less experienced users that it is OK to use straight sudo to run graphical applications as root. –  Eliah Kagan Jun 25 '12 at 0:23

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.

share|improve this answer
1  
Using sudo with graphical applications is NOT a good idea. Use gksu or if you must sudo -i. –  Seth Feb 20 at 17:05
    
@Seth: Updated. Also... A little explanation as to why would not be remiss, rather than just cryptically saying it's not a good idea. –  Syndog Feb 20 at 19:34
    
An interesting thread on the topic : crunchbang.org/forums/viewtopic.php?id=8468 –  Syndog Feb 20 at 19:47
    
here: askubuntu.com/questions/11760/… –  Seth Feb 20 at 20:36

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
share|improve this answer

Im posting this in-respone to the question @Chris asked in comments :

Suppose you want to create a launcher which will open "file manager(nautilus)" as root. Then you can do this:

  1. open terminal. Type: sudo gedit /usr/share/applications/nautilus_root.desktop

    Hit enter. When asked, enter your login password and hit enter. This will open gedit(text editor). Now, paste the following there:

[DesktopEntry]
Encoding=UTF-8
Name=Nautilus(Root)
Comment=FileManager
Exec=gksu nautilus
Icon=file-manager
Categories=System;
Type=Application
Terminal=0

Now, just save it and exit. You are done. Now if you search on dash then you will find a new launcher "Nautilus (Root)". Clicking this will ask you password, and upon authentication nautilus will be opened as root.

Note: Be careful when you are running "Nautilus (Root)". In this mode you can delete almost anything from /

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.