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
  • 82,471
  • 12
  • 195
  • 299
Ramvignesh
  • 1,802
  • 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

Sergiy Kolodyazhnyy
  • 103,293
  • 19
  • 273
  • 492
  • Does this works for Raspberry PI ? I had installed but there's no something like `run as root` in context menu. – huang Dec 21 '20 at 01:20
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
  • 82,471
  • 12
  • 195
  • 299
  • Use `sudo apt-get install nautilus-admin` method instead of making your own system scripts. Then you will get updates when/id needed. – Soren A Jun 15 '17 at 10:58
  • @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. – Jacob Vlijm Jun 15 '17 at 11:09
  • 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. – Soren A Jun 15 '17 at 11:21
  • @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. – Jacob Vlijm Jun 15 '17 at 11:23