Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've read the comunity "RootSudo" documentation and am interested in this line:

You should never use normal sudo to start graphical applications as Root.

Why? What is the difference? Please provide a simple explanation, as I'm just a normal desktop user.

share|improve this question
up vote 73 down vote accepted

Graphical applications often store settings and other user-specific data in configuration files written inside the user's home folder. The main mechanism applications use to determine what they should use as the user's home folder is the HOME environment variable. (You can inspect it yourself with echo $HOME).

Suppose you're running gedit (a graphical text editor) as root. If you run sudo gedit, HOME will continue to point toward your home directory, even though the program is running as root. Consequently, gedit will write configuration files as root into your home directory. This will sometimes result in the configuration files being owned by root and thus inaccessible to you (when you later run the program as yourself and not as root). This mainly happens when the application has to create a new configuration file. Newly created files, by default, are owned by the user who creates them (who in this case is root, not you).

That's the primary reason why you should run graphical applications with a graphical sudo frontend rather than with straight sudo. In Ubuntu and most of its derivatives (including Xubuntu and Lubuntu), the standard graphical frontend is gksu/gksudo. In Kubuntu it is kdesudo. (It depends on the desktop environment being used.)

If you want to use sudo directly to run a graphical application like gedit, you can run:

sudo -H gedit

The -H flag makes sudo set HOME to point to root's home folder (which is /root).

That still won't automatically handle the ownership of .Xauthority by copying it to a temp folder (this is the other thing that graphical sudo frontends take care of for you). But in the infrequent event that .Xauthority is inaccessible, you'll get an error saying it is, and then you can fix the problem by deleting it (sudo rm ~/.Xauthority), as it's automatically regenerated. Thus, protecting .Xauthority's ownership and permissions is less important than protecting the ownership and permissions of configuration files.

In contrast to a root-owned .Xauthority, when configuration files become owned as root, it's not always as obvious what the problem is (because graphical programs will often run, but not work very well, and output any useful errors to the console). And it's sometimes a bigger hassle to fix, especially if you're in a situation where you want one or more files in your home directory to be owned by someone other than you (because then you cannot fix it simply by recursively chowning all your files back to yourself).

Therefore, sudo (at least without -H) should not be used to run a graphical application unless you are highly familiar with the app's inner workings and know for sure that it does not ever attempt to write any configuration files.

share|improve this answer
Thanks for your explanation, now I get the idea of using gksudo instead of sudo. – Nur Mar 20 '13 at 4:42
Can I become the owner of all configuration files (or any files) on my Home directory again, if these file has been owned by root? – Nur Mar 20 '13 at 4:46
@Nur Assuming there are no files in your home directory that you want to be owned by any other user or that you want to have any other group membership (for sharing), you can run: sudo chmod -R $USER:$USER ~ Unfortunately, those criteria don't always apply. If you have any files where you need to preserve the group owner, you can run sudo chmod -R $USER ~. This is usually sufficient. (If you have files need to be owned by another user in your home directory, even that will be a problem.) – Eliah Kagan Mar 20 '13 at 5:46
I just want these files belong to me, thanks. – Nur Mar 20 '13 at 5:53
@Nur If you haven't had any errors or problems, then even if you've been running graphical applications as root with straight sudo, it's possible that you've been fortunate enough that you don't have any root-owned configuration files. (This could happen if it never had to create a file, which is the main circumstance where a file becomes owned by root.) If you haven't had any problems, I wouldn't worry. – Eliah Kagan Mar 20 '13 at 5:54

Simply put:

This prevents files in your home directory becoming owned by root.

Read it here. Also, possibly a duplicate of What is the difference between "gksudo nautilus" and "sudo nautilus"?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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