66

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?

2
  • You could also try installing nemo (linux mint file browser), which has an "open as root" option.
    – user132550
    Feb 16, 2013 at 11:06
  • 1
    sudo su nautilus this worked for me too, assuming you set up your root password and sign in
    – bmendonc
    Jul 1, 2013 at 0:16

10 Answers 10

51

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

8
  • FYI After installing nautilus-admin and running $ nautilus -q it generates 5 error messages in Ubuntu 16.04.3 with kernel 4.14.19, the first of which is (nautilus:14964): GLib-GIO-CRITICAL **: g_dbus_interface_skeleton_unexport: assertion 'interface_->priv->connections != NULL' failed Feb 21, 2018 at 1:39
  • @WinEunuuchs2Unix I get the same 5 error messages. I removed nautius-admin and still get these errors. . So I can't verify if the errors are caused by nautilus-admin. On the other hand, killall anutilus kills it without any errors. finally, I get a different error in Ubuntu 17.04.
    – user68186
    Feb 21, 2018 at 14:24
  • I must point out admin works perfectly. Feb 21, 2018 at 15:50
  • When I click Open as Administrator for folder, it asks password and then nothing is happen (Ubuntu 17.10 Gnome). Any way to fix this?
    – Pavel
    Feb 25, 2018 at 18:51
  • Use X.org rather than wayland.
    – user68186
    Feb 25, 2018 at 22:43
42

Try:

gksudo nautilus

Then type your own password just like when using sudo.

Gksudo man page: http://linux.die.net/man/1/gksudo

6
  • yes, I type my own password ,but no folder window open up.
    – Pho swan
    Jun 28, 2012 at 7:17
  • 1
    I use Ubuntu 12.04 LTS 2 week ago, and i m ok will gksu nautilus command. and yesterday, I face with that problem, type comand " gksu nautilus / " and I type my password . no folder window open up .. so, i cant edit some file in root.
    – Pho swan
    Jun 28, 2012 at 7:26
  • what about: "DISPLAY=:0 gksudo nautilus" or debug mode "gksudo -d nautilus"
    – jaywink
    Jun 28, 2012 at 9:35
  • 8
    gksudo didn't work for ubuntu 17 and later! Jul 11, 2018 at 19:16
  • Answer by @elomage worked for 19.10.
    – bmello
    Oct 29, 2019 at 15:24
15

When opening Nautilus with root privileges, it is best to use the command

gksudo

unless your root account is unlocked, and in that case, Ubuntu discourages this.

The reason for the "gk" is because sudo, by itself, doesn't perform the necessary actions automatically to properly run graphical applications as another user.

However for instance, if you were on a KDE system such as Kubuntu, you would want to issue the command

kdesudo

p.s. Do not leave your Nautilus root window open when you are not using it,then forgetting about it, as using a window you do not know is root is a bad idea.

For more information view the Ubuntu man page for gksudo here.

3
  • Unfortunately not works in Ubuntu 17.10: Failed to run nautilus as user root. Unable to copy the user's Xauthorization file.
    – Pavel
    Feb 25, 2018 at 18:49
  • outdated in 18.04.
    – somethis
    Aug 30, 2019 at 23:29
  • Answer by @elomage worked for 19.10.
    – bmello
    Oct 29, 2019 at 15:20
11

If you find yourself opening nautilus as root often, I would recommend adding the option to the right-click menu in Unity: (it uses the same command as the top answer, gksu nautilus).

You will need to edit a *.desktop file in order to add the menu option, and you have two choices:

  • /usr/share/applications/nautilus.desktop (requires root access to edit) - The menu option will be added for all users. Note that you may need to re-edit this file, adding the option if an update to Nautilus occurrs that overwrites your changes.
  • ~/.local/share/applications/nautilus.desktop (If you can't find it there, make a duplicate of the one found in /usr/share/applications/, and save it to this new location) - The menu option will only be available for the specified user, and is considered "better practice". Note that if you already have it docked to your Unity bar, you will need to choose Unlock from Launcher on your existing Nautilus icon (by default shows up as named Files), then re-add your "custom" version. These changes should stay even if Nautilus gets an update.

Edit the text file nautilus.desktop, adding the following block of code (you can use the existing two blocks as a template):

[Desktop Action RootWindow]
Name=Open a Root Window
Exec=gksu nautilus
OnlyShowIn=Unity;

Next, add the new action to the list (should be at around line 18 of the text file):

Actions=Window;RootWindow;

Now right-clicking the text editor window in Unity brings up this handy new option:

Ubuntu Unity: Open Nautilus as Root

2
  • I was trying this except for file nautilus.desktop is not exist on my Ubuntu 15.10 !
    – user161480
    Dec 15, 2015 at 9:36
  • @IhabAbdel-Rahim That's strange, it exists on mine at /usr/share/applications/nautilus.desktop, and I just did a fresh install a month ago.
    – IQAndreas
    Dec 18, 2015 at 21:34
7

"sudo nautilus" works for me. Here are some alternatives:

Enter superuser mode with "sudo su" in the terminal (will ask for your password), then run the commands from there:

sudo su
nautilus

Another alternative is to use something else for file exploration than nautilus, something that does not require graphical environment. GNU Midnight Commander - mc comes to mind. You can install and run it like this:

sudo apt-get install mc
mc

Your error messages suggest that the root "Cannot open display". The reason might be that the DISPLAY environment is not properly set up. You can check it from the terminal like this:

printenv | grep DISPLAY

You should see something like DISPLAY=:0.0 in response. If not, take care of the display environment for the root first.

1
  • Thanks. "sudo nautilus" didn't work for 19.10, but "sudo su / nautilus" did.
    – bmello
    Oct 29, 2019 at 15:21
3

Completely-GUI way

No command is needed! Here is the GUI way:

  1. Open Nautilus using one of the following ways:

    • Press Super key, and search for "Files" (or "Nautilus").

    • Open Activities, and search for "Files" (or "Nautilus").

  2. In the sidebar (on the left-hand-side), click on "Other Locations".

  3. An address field appears on the bottom of Nautilus, with the text of "Enter server address...". Enter admin: (or admin:///), and press Enter (or click on the "Connect" button).

  4. Enter your root password when prompted.

Enjoy working as administrator (but be really careful)!

Note: The benefit of using this way over others is that you can safely switch between root and non-root. You can use Nautilus as a root user and as a non-root one (i.e. the user yourself) in two separated tabs. This way, you will be ensure that, for instance, you will not make a file in your home directory with root permissions.

Add it to bookmarks

Note: By adding administration explorer to bookmarks, sometimes Nautilus prompt you for root password when you open it.

  1. Follow the steps in the section above. Navigate to the directory of choice if needed, e.g. /bin.

  2. Use one of the following ways:

    • Use this shortcut: Ctrl + D.

    • From the toolbar on top, click on more button (with three dots). From the appeared drop-down menu, click on "Bookmark this location" button. The button is on the center of the first three buttons set.

    • From the location bar, click on "Administrator Root" or "/" (i.e. the folder you want to bookmark). From the appeared list, click on "Add to bookmarks".

  3. To rename the bookmark you created, right click on it and choose "Rename...". Now you can enter a new name for it, e.g. "Root".

By clicking on your new bookmark, you can access files and directories as root. For me, it prompt the root password if I haven't enter it recently.

Hope it helps!

1
  • 1
    Great solution with the bookmark! Thank you Aug 23, 2019 at 13:13
1

Nautilus Admin (nautilus-admin) is a simple Python extension for the Nautilus file manager that adds some administrative actions to the right-click menu:

  • Open as Administrator: opens a folder in a new Nautilus window running with administrator (root) privileges.
  • Edit as Administrator: opens a file in a Gedit window running with administrator (root) privileges.

To install Nautilus Admin in all currently supported versions of Ubuntu open the terminal and type:

sudo apt install nautilus-admin
0

Open terminal and type the following:

sessionfile=$(find "${HOME}/.dbus/session-bus/" -type f)
export $(grep "DBUS_SESSION_BUS_ADDRESS=" "${sessionfile}" | sed '/^#/d')

Try running your command again (sudo nautilus).

0

If you are running Ubuntu Live or Persistent install, sudo nautilus is ok, everything on the drive, except home, is already owned by root and is read only.

If you create, copy or modify a file or folder, inside the home folder on the persistent drive as root using sudo nautilus the permissions will be restored to owner on reboot. If you create, copy or modify a file on a different drive using sudo nautilus the permissions will revert to owner once the usb drive is shut down.

4
  • Nope, the home directory of the default user ubuntu is owned by that user. If one uses sudo for graphical applications it may still mess up the permissions (however they're restored after reboot because the changes are not persistent). -1 May 2, 2017 at 15:47
  • Are you saying it is not OK to use sudo nautilus while using a Live or Persistent install, that it can damage something or permanently mess up permissions? Can you be a little more specific? What is the worst that can happen? I have used sudo nautilus many times working with live/persistent installs since gksu was removed and have never had a problem with permissions. I have spent the last four hours playing with a 17.04 persistent flash drive and sudo nautilus and have not been able to create a problem. May 2, 2017 at 22:48
  • I'm saying that in principle the live system is no different than a proper installation regarding the side-effects of sudo nautilus, however, without persistence, the effects are easily reversed with a reboot. You not encountering an undesirable side-effect is no sufficient evidence that there are none. In fact, this side-effect is a well documented behaviour that may appear under the right circumstances which do not depend on a regular Ubuntu installation. May 3, 2017 at 0:14
  • Yes please, I am asking you to tell me a well documented behavior that I can repeat to convince myself that you are right. May 3, 2017 at 0:31
-2

Edit your /etc/profile with:

sudo nano /etc/profile

Then add this to the end of the file:

xhost +local:all

Ctrl+X to quit.
Y to confirm.
Enter to confirm path.
Done.

Run anything as root.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .