Can I open a file as root by just using the right click menu

15,750

Solution 1

You need the admin extension

$ apt-cache search nautilus | grep admin
nautilus-admin - Extension for Nautilus to do administrative operations

Install it with sudo apt-get install nautilus-admin

Solution 2

I tested the solution from here, and it works fine (running 14.04/nautilus).

enter image description here

To not post a link-only answer:

  1. install gksu

    sudo apt-get install gksu
    
  2. Navigate to ~/.local/share/nautilus/scripts

  3. Create and open an empty file, name it open-as-administrator, paste the script below:

    #!/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. Make the script executable

  5. Either log out and back in, or run:

    nautilus -q
    

AGAIN: the script is not mine! found it on http://ubuntuhandbook.org

Share:
15,750

Related videos on Youtube

Ramvignesh
Author by

Ramvignesh

Updated on September 18, 2022

Comments

  • Ramvignesh
    Ramvignesh almost 2 years

    Opening file as root is possible with sudo. But, how to right click a file and make it run as root ?

    I am using nautilus.

  • Soren A
    Soren A about 7 years
    Use sudo apt-get install nautilus-admin method instead of making your own system scripts. Then you will get updates when/id needed.
  • Jacob Vlijm
    Jacob Vlijm about 7 years
    @SorenA what do you suggest, never post your own alternative if another solution exists? Furthermore, the concept of this answer could be usefull to someone to perform other actions on the file, not available in existing nautilus actions.
  • Soren A
    Soren A about 7 years
    What I mean is never to propose a "manual" unsupported solution, when you know that a working supported one exists. As for the concept part you could have a point, but I fear that it will confuse more ppl than it will help.
  • Jacob Vlijm
    Jacob Vlijm about 7 years
    @SorenA there could be a million reasons to use a "home-made" alternative. Flexibility is one; functionality can easily be changed or fine tuned. Even only for that reason, the answer is useful. Confuse? then don't play around with it if you don't understand.
  • Joe Huang
    Joe Huang over 3 years
    Does this works for Raspberry PI ? I had installed but there's no something like run as root in context menu.