5

I am seeking for a way to make run as root option shown in "Files" context menu of Unity so, I get rid of using terminal every time I want to access nautilus as a root.

enter image description here

I found the original concept here, except for I didn`t find the file need to edit: How do I start Nautilus as root?

7
  • What is your Ubuntu version? Dec 15, 2015 at 9:42
  • @JacobVlijm it is 15.10
    – user161480
    Dec 15, 2015 at 9:46
  • Ok. thanks will post an answer in a few minutes. Dec 15, 2015 at 9:47
  • @Maythux I don't think so. The (this) question is on how to add it to the Unity Launcher as a right- click option (shown in "Files" context menu of Unity). Also, 15.10 uses a different ` .desktop` file in the launcher, so even if you take the answers as a criterion (which you shouldn't) , it would be outdated. Dec 15, 2015 at 10:10
  • @Maythux again, the question is the criterion, not possible answer(s), and the answer is even outdated for 15.10. Dec 15, 2015 at 10:14

3 Answers 3

4

To add the option to run as root to the nautilus (Files) launcher:

  1. Copy the .desktop file, representing nautilus in the launcher, from the global directory /usr/share/applications to ~/.local/share/applications

    which is on 14.04 and 14.10 : nautilus.desktop:

    cp /usr/share/applications/nautilus.desktop ~/.local/share/applications
    

    and on 15.04 and 15.10 : org.gnome.Nautilus.desktop

    cp /usr/share/applications/org.gnome.Nautilus.desktop ~/.local/share/applications
    
  2. Open the file with (e.g.) gedit, look for the line:

    Actions=Window;
    

    Change it into:

    Actions=Window;Open as root;
    

    Add to the very end of the file:

    [Desktop Action Open as root]
    Name=Open as root
    Exec=gksu nautilus
    

    Save and close the file.

  3. Install gksu, to be able to enter your password via GUI:

    enter image description here

    sudo apt-get install gksu
    
  4. Finally, log out/in to make Unity "aware" of the local, edited .desktop file.

    enter image description here

That's about it.

Note

In some cases, you might have some doubts on what is the correct .desktop file to edit. This question on nautilus is a good example, since nautilus represents itself in a different .desktop file in the launcher on different Ubuntu versions, while nautilus has multiple .desktop files in /usr/share/applications.

To be sure to edit the correct one, simply run:

gsettings get com.canonical.Unity.Launcher favorites

which will output a list of current .desktop files, used in the launcher.

5
  • 1
    Or just use nemo... >:-)
    – Fabby
    Dec 19, 2015 at 19:49
  • Comment by derwiwie Note that in order for the above gsettings command to print nautilus at all, nautilus needs to be locked/pinned to the launcher.
    – Elder Geek
    Feb 9, 2017 at 17:23
  • @Fabby "Be Nice :)" about gksu and nautilus: meta.askubuntu.com/questions/17687/… Feb 21, 2018 at 1:34
  • @WinEunuuchs2Unix upvoted your answer there... Never in chat any more?
    – Fabby
    Feb 21, 2018 at 20:21
  • 1
    @Fabby No. I'm kind of an anti-war guy and the HRC extremists (or some people like that) leveled a 30 day chat ban against me last year. So I decided it was a bad place to hang out. Thanks for upvoting my anti-anti-gksu gedit answer though :) Feb 22, 2018 at 0:31
4

Use pkexec instead of gksu

The use of gksu and gksudo is not recommended any more. The recommended method is to use Polkit. The easiest way to add Polkit files for Nautilus is to install nautilus-admin

To install nautilus-admin in Ubuntu, open a terminal by pressing Ctrl+Alt+T and use the following command:

sudo apt-get install nautilus-admin

The rest involves editing the `nautilus.desktop file and adding the correct command:

  1. Copy the nautilus.desktop file, representing nautilus in the launcher, from the global directory /usr/share/applications to ~/.local/share/applications

    cp /usr/share/applications/nautilus.desktop ~/.local/share/applications

  2. Open the file with (e.g.) gedit, look for the line:

    Actions=Window;

Change it into:

Actions=Window;Open as Administrator;

Add to the very end of the file:

[Desktop Action Open as Administrator]
Name=Open as Administrator
Exec=pkexec nautilus

Save and close the file.

The added bonus of installing nautilus-admin is that within Nautilus you will also get Open as Administrator / Edit as Administrator items for folders / text files in the right click context menu. See How do I start Nautilus as root? for more details.

Hope this helps

1

For me under Ubuntu 16.10 the relevant .desktop file for nautilus was

/usr/share/applications/nautilus.desktop

Even though gsettings get com.canonical.Unity.Launcher favorites returned application://org.gnome.Nautilus.desktop

Also note, that in order for the above gsettings command to print nautilus at all, nautilus needs to be locked/pinned to the launcher.

0

You must log in to answer this question.