10

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.

Jacob Vlijm
  • 85,475
Ramvignesh
  • 1,862
  • 6
  • 20
  • 31

2 Answers2

10

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

1

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

Jacob Vlijm
  • 85,475