Ubuntu 14.04: Add ‘Open As Root/Administrator’ to Context Menu

Last updated: February 15, 2018

ubuntu 14.04 context menu

 

This simple tutorial will show you how to add ‘Open As Root’ or ‘Open As Administrator’ option to context menu so that you can easily edit / open file folders as super user privilege within Nautilus file browser.

Open as Administrator ubuntu 14.04

There’s now a Nautilus extension (see the link) adds administrative actions to Nautilus context menu. It’s easy to install and supports for all current Ubuntu releases.

To get started:

1. Open Ubuntu Software Center. Search for and make sure the package gksu is installed. gksu allows graphical programs to ask a user’s password to run program as root / administrator.

gksu ubuntu 14.04

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’ or ‘open-as-root’

open as administtrator ubuntu 14.04

3. Edit and paste following lines into the file

#!/bin/bash
#
# 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
obj="$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
else
base="`echo $NAUTILUS_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g'`"
obj="$base/${1##*/}"
fi
# Determine the type and run as ROOT
if [ -f "$obj" ]; then
gksu gedit "$obj"
elif [ -d "$obj" ]; then
gksu nautilus "$obj"
fi

exit 0

4. Press Ctrl+Alt+T to open the terminal. When it opens, run the command below to make executable:

cd .local/share/nautilus/scripts/ && chmod 0755 open-as-administrator

5. Finally restart Nautilus via command nautilus -q, or just log out and back in.

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee: https://ko-fi.com/ubuntuhandbook1

10 responses to Ubuntu 14.04: Add ‘Open As Root/Administrator’ to Context Menu

  1. Many thanks for the explanation Ji m. In fact, you only need to write as follows:

    gksudo nautilus

    in a text document and place within the folder location and then make it executable. You may need to first install:

    gksu

    sudo apt-get install gksu

    So if you want to open the terminal as root, write within a separate text dokument:

    gksudo gnome-terminal

    To create a launcher:

    gnome-desktop-item-edit Desktop – create-new

    However, the Desktop folder is language specific. If You’re using another language, You’ll need to translate the word “Desktop” to the specific language. For instance in my case is the word “Skrivebord” (Danish):

    gnome-desktop-item-edit Skrivebord – create-new

    You’ll then have the above commands within the context menu.

    I still find Ubuntu 14.04 environment a bit insufficient which I expect will be fixed soon.

    • Your way is not working. If you do it in so, only a new nautilus is opening as root and not the direkctoy of the choice…

      The script is working as aspekted, Thank you for this. I never had so much work to get a “productiv” system…

  2. I get an error at times

    Unable to create a required folder. Please create the following folder, or set permissions such that it can be created:
    /root/.config/nautilus

  3. the srcript finally worked when i combined it with the command from user frog in discussion below thx guys

  4. Thanks.
    It’s also good to add option to open executable file. Just before ‘fi’ at the end add the following.
    elif [ -x “$obj” ]; then
    gksu “$obj”

  5. And why not just use :

    if [ -d “$1” ]; then
    gksu nautilus “$1”
    elif [ -x “$1” ]; then
    gksu “./$1”
    elif [ -f “$1” ]; then
    gksu gedit “$1”
    fi

    as the whole script?

  6. Thank you Ji m.
    The code works flawlessly.
    Now I have a working nautilus.

  7. Hello hanks for the script Ji m, but in Ubuntu 14.04 is needed add this line in /etc/sudoers (sudo visudo)

    Defaults env_keep+=”DISPLAY XAUTHORITY”

    In my case, i write this script

    #!/bin/bash
    ####################################################################
    # Abrir Como Administrador
    # Escrito Por Jesús Navarro
    ####################################################################
    # Requerimientos: sudo, gksudo, libgnome2-bin
    #
    # Para asegurar el funcionamiento instale como
    # administrador desde el terminal…
    # sudo apt-get install sudo gksudo libgnome2-bin
    ####################################################################
    # Instalación:
    #
    # Coloque este Script en la carpeta Nautilus-scripts
    # (/home/tuUsaurio/.local/share/nautilus/scripts)
    #
    # Asegurese que el archivo tiene permiso de ejecución,
    # en el terminal con tu usuario
    # chmod +x /home/tuUsaurio/.local/share/nautilus/scripts/Abrir\ Como\ Administrador
    ####################################################################

    while [ $# -gt 0 ]; do
    uri=$1
    gksudo gnome-open “$uri” &
    shift
    done
    exit 0

    This work for me

  8. Thank a lot Ji m ,its working perfectly in my 14.04

  9. Joseph William March 2, 2016 at 4:20 pm

    shutting off and disabling…. sorry when i type fast the keyboard doesnt always come accurate on spelling