Adding run as root for nautilus in unity
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.
I found the original concept here, except for I didn`t find the file need to edit: How do I start Nautilus as root?
To add the option to run as root to the nautilus (Files
) launcher:
-
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
-
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.
-
Install
gksu
, to be able to enter your password via GUI:sudo apt-get install gksu
-
Finally, log out/in to make Unity "aware" of the local, edited
.desktop
file.
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.
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:
-
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
-
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
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.