The nautilus file manager (used in Gnome, Unity and Budgie) lacks the native ability to open files with root or administrative) privileges. At one time, a person could open the file manager using the command gksu, granting the user admin privileges. Unfortunately, gksu hasn’t been updated in years, prompting many distributions to drop it from their repositories.

Enter pkexec, the modern day replacement for gksu. Just like gksu, this command can be used to open a graphical program with root privileges. To use this command, you must have a PolicyKit file installed in /usr/share/polkit-1/actions/ for the app you’re trying to run as root. Unfortunately, most distribution don’t include this for Nautilus or the Gedit text editor.

Fortunately, the folks at WebUpD8.com have provided the necessary PolicyKit files via their GitHub page. In this tutorial, I will demonstrate how to download and install these files, as well as set up an entry in the right click menu of Nautilus.

A note from AJ:  Be sure to check out the video tutorial!

Getting the PolicyKit Files

Let’s begin by downloading the PolicyKit files needed to perform these actions. WebUpD8 provides these via their GitHub page, so we can download from there. Open a terminal and enter the following commands:

wget https://raw.githubusercontent.com/hotice/webupd8/master/org.gnome.nautilus.policy -O /tmp/org.gnome.nautilus.policy
sudo cp /tmp/org.gnome.nautilus.policy /usr/share/polkit-1/actions/
wget https://raw.githubusercontent.com/hotice/webupd8/master/org.gnome.gedit.policy -O /tmp/org.gnome.gedit.policy
sudo cp /tmp/org.gnome.gedit.policy /usr/share/polkit-1/actions/

This will download and install the two PolicyKit files needed. One this is complete, both nautilus and gedit can be opened with root access from the command line using the command pkexec nautilus and pkexec gedit respectively.

Adding to the Nautilus drop-down menu

To access our new root function from the nautilus right-click menu, we will use a tool called Nautilus Actions. Most distributions include it in their repositories, but just in case yours doesn’t, here is a link to the Nautilus Actions homepage: http://www.nautilus-actions.org/
Open the nautilus actions tool, and click the define new action button. In the Context Label section, name this action Edit as Root. Under the Actions tab, check the boxes for Display item in selection context menu, Display item in location context menu, Display item in the toolbar, and Use same label for icon in the toolbar. Select an icon (if desired) and then move on to the Command tab.
Under profile, label the action as Root. Under path, add in pkexec, and Parameters are set to gedit %f. Change the working directory to %d (if it isn’t already). All of the rest of the setting can remain at their default values. Save the action by clicking the arrow down key (directly below Edit in the title bar).
Click define new action button again, this time entering Open folder as Root in the Context label. Once again, check the following boxes: Display item in selection context menu, Display item in location context menu, Display item in the toolbar, and Use same label for icon in the toolbar. Choose and icon, then move on to the Command tab.
The profile label will once again be root, and the path is pkexec. Under parameters, enter nautilus %d, and the directory is once again %d. Save this action.
At this point, the process is complete. When right clicking on a folder in Nautilus, you will find Open folder as root has been added. Selection this option will bring up a dialog box that asks for the admin password. After entering the password, a new instance of nautilus will open with root privileges. Text files listed in nautilus can likewise be edited as root via the right click menu; just look for the entry edit as root.
I hope this tutorial has proven useful. Be sure to check out the companion YouTube video demonstrating this tutorial. As always, leave comments and questions below, and I’ll try to get to them ASAP.  Thanks for reading, and be sure to share this post on social media.

Stay up to date with the weekly newsletter!