This question already has an answer here:

When using gedit , i always need to edit file in /etc/ or /usr/ which need to be root. So i created a Launcher shortcut on the left with command sudo gedit.

So every time i click the icon on the left Launcher, gedit will started as root. But the problem is that, when i modified other files, such as files in /home, the owner of file will also be changed to root. I don't want to do this, i just want to save this file without modifying its owner, and i don't want to bother every time to restart gedit as root to modify files owned by root. How to do it?

marked as duplicate by Eliah Kagan, Eric Carvalho, Charles Green, ravery, Videonauth Nov 22 '17 at 4:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    You can change ownership of a file by executing chown newusername /path/to/file. If the file is currently owned by root or another user different from yours, you have to use it with sudo. – Byte Commander Feb 22 '15 at 11:28
  • 1
    That is why I posted this as a comment and not as an answer. I don't think that gedit has an option like "save as user...". You only can create two different launchers (with and without gksu) then and edit the file with the respectively correct editor. – Byte Commander Feb 22 '15 at 11:32
  • 2
    ehm... make a second launcher that does not have "sudo"? ;) but you really need to ask yourself a question: "why do you need to edit files in /etc/ or /usr/ so often?" I can not even remember the last time I needed to edit a file in there. Maybe it was /etc/mysql/my.cnf but it has been months ago. – Rinzwind Feb 22 '15 at 15:43
  • 1
    Extra: if the file is made by you and something personal I would suggest considering placing it elsewhere. For instance /usr/local/ and change the owner from root to your user or place it in /home/$USER ; please try to limit altering files with admin as much as possible. Linux in general is set up such that alteration of files outside your own is not needed that often: you set up your system once and are done changing it unless you have some new software. In general all settings should have either a gui or should in in /home/ anyways. – Rinzwind Feb 22 '15 at 15:56
  • 3
    basically... if you don't want it to be owned by root... don't run it as root... – Wilf Feb 23 '15 at 14:56

Add a shortcut to your launcher.

I would not change the main command of the gedit launcher. Do the following:

  1. Never edit the default launcher, first copy the one from /usr/share/applications to ~/.local/share/applications:

    cp /usr/share/applications/gedit.desktop ~/.local/share/applications/gedit.desktop
  2. Edit the file with... gedit (not with gksudo)

    gedit ~/.local/share/applications/gedit.desktop

    Look for the line, starting with Actions=, Add gedit with gksu;:

    Actions=Window;Document;gedit with gksu;
  3. To the very end of the file add the shortcut section:

    [Desktop Action gedit with gksu]
    Name=gedit with gksu
    Exec=gksu gedit
  4. Done, Now if you click on the icon, gedit starts "normally", while you have gksu gedit available as a shortcut:

    enter image description here

Directly browse for a file to edit

If you often edit files with gksu with gedit, you can also directly call a (Zenity) browser from the launcher, to open your files with gksu. You can "save" one step when opening files with gksu then:

enter image description here

enter image description here

  1. Copy & open the local .desktop file as in the first option
  2. Look for the line, starting with Actions=, Add gksu gedit with filebrowser;:

    Actions=Window;Document;gksu gedit with filebrowser;
  3. At the very end of the file, add the shortcut section:

    [Desktop Action gksu gedit with filebrowser]
    Name=gksu gedit with filebrowser
    Exec=sh -c "gksu gedit $(zenity --file-selection --title='Select a file')"


gksu is not installed by default, you will probably have to install it if you use the commands mentioned:

sudo apt-get install gksu
  • It's cool.I found gksudo before your post, and answered my own question but get downvoted. But when i use gksudo, sublime(my editor) always get non-response, so your post solved my problem perfectly! – demonguy Feb 23 '15 at 7:52
  • Perfect! glad it works. If you always use gksudo (or gksu) instead of having it as an option, you still have the problem that files created are owned by root. – Jacob Vlijm Feb 23 '15 at 7:54

You can modify the owner by opening a terminal up and typing in `chown user /path/to/file like Byte Commander stated you can do this. However, setting the the owner isnt enough. because you're accessing a root placed file in a root only access folder. You need to give your self full permissions.

To make your self like root for that file only you need to type in a terminal

chmod u+aw filenamewithextension

You must do this while being in the file's location.

After this, you can gedit without sudo and never have the system modify the owner. Do not sudo gedit or it will!

  • You probably wouldn't mess with the permissions of /etc for instance, nor with the files in it. – Jacob Vlijm Feb 23 '15 at 7:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.