Adding run as root for nautilus in unity

8,825

Solution 1

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.

Solution 2

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

Solution 3

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.

Share:
8,825

Related videos on Youtube

Community
Author by

Community

Updated on September 18, 2022

Comments

  • Community
    Community over 1 year

    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?

    • Admin
      Admin over 8 years
      What is your Ubuntu version?
    • Admin
      Admin over 8 years
      @JacobVlijm it is 15.10
    • Admin
      Admin over 8 years
      Ok. thanks will post an answer in a few minutes.
    • Admin
      Admin over 8 years
      @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.
    • Admin
      Admin over 8 years
      @Maythux again, the question is the criterion, not possible answer(s), and the answer is even outdated for 15.10.
    • Admin
      Admin over 8 years
      @JacobVlijm ok its my fault.sorry
    • Admin
      Admin about 7 years
  • Fabby
    Fabby over 8 years
    Or just use nemo... >:-)
  • Elder Geek
    Elder Geek about 7 years
    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.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix about 6 years
    @Fabby "Be Nice :)" about gksu and nautilus: meta.askubuntu.com/questions/17687/…
  • Fabby
    Fabby about 6 years
    @WinEunuuchs2Unix upvoted your answer there... Never in chat any more?
  • WinEunuuchs2Unix
    WinEunuuchs2Unix about 6 years
    @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 :)