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.


2 Answers 2


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

  • Does this works for Raspberry PI ? I had installed but there's no something like run as root in context menu.
    – huang
    Dec 21, 2020 at 1:20

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:

    # 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. 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

  • 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, 2017 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. Jun 15, 2017 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, 2017 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. Jun 15, 2017 at 11:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .