Is there an easier or more 'correct' way to open gedit as root?

Use gksudo gedit.

gksudo is the equivalent of sudo for graphical programs, which are not safe to run using sudo.


I find myself running gedit as root quite frequently, so I added the option to the right-click menu in Unity (it uses the same command as the selected answer, gksu gedit).

You will need to edit a *.desktop file in order to add the menu option, and you have two choices:

  • /usr/share/applications/gedit.desktop (requires root access to edit) - The menu option will be added for all users. Note that you may need to re-edit this file, adding the option if an update to gedit occurrs that overwrites your changes.
  • ~/.local/share/applications/gedit.desktop (If you can't find it there, make a duplicate of the one found in /usr/share/applications/, and save it to this new location) - The menu option will only be available for the specified user, and is considered "better practice". Note that if you already have it docked to your Unity bar, you will need to choose Unlock from Launcher on your existing GEdit icon, then re-add your "custom" version. These changes should stay even if GEdit gets an update.

Edit the text file gedit.desktop, adding the following block of code (you can use the existing two blocks as a template):

[Desktop Action RootWindow]
Name=Open a Root Window
Exec=gksu gedit
OnlyShowIn=Unity;

Next, add the new action to the list (should be at around line 19 of the text file):

Actions=Window;Document;RootWindow;

Now right-clicking the text editor window in Unity brings up this handy new option:

Ubuntu Unity: Open Gedit as Root


Use admin:// in front of the file name which brings up the standard GUI password prompt for your respective WM/shell.

So for example, if you wanted to edit your repos, instead of typing sudo gedit /etc/apt/sources.list you would type gedit admin:///etc/apt/sources.list. It works for basically all GUI programs, not just Gedit.