Ubuntu – How to start Nautilus as root


I've got a problem with Nautilus in Ubuntu 12.04 LTS.

When I run the command gksu nautilus /, the password ask box appears and I type my super-user password, then the password box disappears and Nautilus is not opened.

When I try to open Nautilus as a normal user in with the command nautilus, the folder is opened.

When I try in terminal

$ sudo nautilus

I got the following error

$ sudo nautilus /

** (nautilus:8523): WARNING **: Command line `dbus-launch --autolaunch=2c8ce9b7da2257c2609b749700000007 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n Could not parse arguments: Cannot open display:

How can I fix this error?

Best Answer

How to run Gedit AND Nautilus as administrator with pkexec instead of gksu or gksudo

GVfs method tested in Ubuntu 18.04

Use the GVfs admin backend, just add admin:// to the beginning of the full path to your preferred directory.

Open Nautilus the usual way and press Ctrl+L to enable typing in the address-bar, and then enter for example admin:///usr/ to open the /usr/ directory.

Enter your admin password when prompted and you will see something like this:

enter image description here

At this point clicking on the folders with locks will open with admin privileges.

You may bookmark a folder that is opened with admin:/// prefix. When you click on such a bookmark later you may be prompted for the admin password again.

Alternatively, from the Terminal open nautilus with the argument admin:///usr/:

nautilus admin:///usr/

to open the /usr/ directory as root in Nautilus.

Editing text files with admin privileges

From Nautilus opened in this way, if you click on a text file that needs admin privileges, you will be prompted for password again, before it opens in your default editor such as Gedit.

If you are using Ubuntu 17.10

The following method does not work with Wayland by default. There are some workarounds. The easiest one is not to use Wayland. How do you switch from Wayland back to Xorg in Ubuntu 17.10? Other alternatives are described in Why don't gksu/gksudo or launching a graphical application with sudo work with Wayland?

Ubuntu will switch back to Xorg by default in 18.04 LTS and the workarounds will not be needed then.

Original answer

Source: WebUpd8

gksu hasn't been updated since 2009 and is not recommended any more. In fact, Ubuntu no longer ships with gksu by default (though it may be installed for many of you, because some apps still depend on it) and it may even be completely removed at some point.

Nautilus admin adds PolicyKit files for both Nautilus and Gedit and it allows opening a file or folder from Nautilus as root, via PolicyKit:

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

And to restart Nautilus use either of the following commands:

nautilus -q or killall nautilus

After this when you right click on a folder you will see:

enter image description here

If you right click on a text file editable by Gedit you will see:

enter image description here

Then you will be prompted for password:

enter image description here

Related question: "Open in terminal" not working on nautilus as root

Finally, installing nautilus-admin also allows opening nautilus as root from the command line. Use the following command instead of gksu or gksudo:

pkexec nautilus 

to open nautilus as root.

Hope this helps

Related Question