How to open files as root via a right click

The following tutorial explains how to add a context menu item that enables a Linux user to open files as the root user when browsing their file system using nautilus. This script feature allows the user to navigate their file system and open or edit any file or directory as the root user of the system. It's a perfect solution for those that are not completely comfortable using terminal commands.

Note: This tutorial assumes your using a Debian based system utilizing Gnome and nautilus. Systems such as Ubuntu or another Debian based derivative. The Ubuntu Live CD was used for this tutorial. Your "$Home/.gnome2" path may vary. In addition, if your attempting this on a Full Blown Debian installation, you will first need to make sure your user has been added to the sudoers list.

Adding a contextual menu item to open as root:

  1. Open a terminal and type sudo su
  2. Then type the following:

    gedit .gnome2/nautilus-scripts/Open\ as\ root

  3. Now add the following to the open document and save the file:

    for uri in $NAUTILUS_SCRIPT_SELECTED_URIS; do

    gksudo "gnome-open $uri" &

    done

  4. Back at the terminal, type:

    sudo chmod +x .gnome2/nautilus-scripts/Open\ as\ root

All set, now when you want to open a file as root, simply right click the file and select Scripts-> Open as root

Note: You may need to restart to see the changes!

Right Click open as root Screenshot:

Open as root, right click context menu item

Similar Portable Linux Posts:

Disclaimer