How to Enable Open as Administrator for Ubuntu 13.10 Nautilus

This quick tip is going to show beginners how to add ‘open as administrator’ or ‘open as root’ into Nautilus context menu in Ubuntu 13.10 Saucy.

With this feature enabled, you can quickly open files and folders in Nautilus with root (super user) privilege. This also works on Linux Mint 16 Petra if you’re using Nautilus 3.8.x.

To get started:

1. Open Ubuntu Software Center, search for and install gksu. It allows graphical programs to ask a user’s password to run program as root / administrator.

2. Open Nautilus file browser, press Ctrl+H to view hidden files & folders. Navigate to USER Home -> .local -> share -> nautilus -> scripts.

Create an empty document under this directory named ‘open-as-administrator’

3. Open this file with Gedit, copy and paste following codes into the file and save.

# this code will determine exactly the path and the type of object,
# then it will decide use gedit or nautilus to open it by ROOT permission
# Determine the path
if [ -e -n $1 ]; then
base="`echo $NAUTILUS_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g'`"
# Determine the type and run as ROOT
if [ -f "$obj" ]; then
gksu gedit "$obj"
elif [ -d "$obj" ]; then
gksu nautilus "$obj"

exit 0

4. Right-click on this file, go to Properties -> Permissions tab. Check the box which says ‘Allow executing file as program’.

Log out and back in, or restart Nautilus by nautilus -q command. Done.