Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

What's difference between sudo and gksudo?

share|improve this question
Good question. Im learning Linux now (You can see that I haven<t found my keyboard layout yet) Haha! – r0ca Oct 23 '10 at 21:24
up vote 19 down vote accepted

sudo asks for the password on the command line, and gksudo pops up a dialog box for it.

share|improve this answer
is that all?............ – oneat Oct 23 '10 at 20:06
yes, thats the difference – knitti Oct 23 '10 at 20:28
gksu(do) also has its own configuration of which environment variables to pass through to the child, separate from su(do)'s own. For example, if your sudoers config specifies !keep_env, the lack of $DISPLAY may prevent graphical applications from running, but gksudo should work. You can find some details at;a=blob;f=common/… or . – ephemient Oct 23 '10 at 21:55
the answer below seems far superior – johny why May 25 '15 at 17:17
I want to emphasize that this is not the crucial difference at all, and this answer is quite misleading to newbies. The major difference is explained here: and the answer below (that @johnywhy linked to) goes a step beyond that to add some nuance to that. Please read the askubuntu question rather than relying on this misleading answer. – sundar Sep 26 '15 at 13:22

gksudo is a GTK-based frontend of sudo(BTW, kdesudo is a Qt-based frontend), however it (by default) handles more environmental variables(HOME, XAUTHORITY, etc.) than sudo thus making running commands as root safer.

As far as I can see only @Logics answer is correct enough (@Ignacio Vazquez-Abrams's is not complete). Here is the try-to-avoid clarification to @Davros @knitti answer/comments (Please kindly remove/edit them when it's not needed):

  1. Although both commands are indeed represents sudo, the UI used is NOT the only difference of the two commands.
  2. Running GUI program is NOT the only situation when you should use gk/kdesudo, instead you should use gk/kdesudo whenever you can't determine whether the command will create/write files to your home directory (which the HOME environment variable points to in the sudo command in some system and situations). Not all GUI apps writes to your home directory and not all CLI apps don't, so the type of command isn't the key point.
  3. You still can use sudo command to launch GUI apps as root (for viewing apps' console output as an example), however you need to handle HOME (and others such as XAUTHORITY, DISPLAY, input-method-related-stuff, etc.) environmental variables correctly so that the launched app won't fail, lose functionality or do really-bad stuff. The following is my current recommendation for using sudo
    • sudo -H <rest of the command>
      • (from sudo section 8 manual page) The -H ( HOME ) option requests that the security policy set the HOME environment variable to the home directory of the target user (root by default) as specified by the password database. Depending on the policy, this may be the default behavior.
      • This should at least prevent files being created in sudo caller's home directory
    • sudo -H DISPLAY=<a working X display name, usually :0> <rest of a GUI program command>
      • This should let <GUI program> executed in a TTY terminal and displayed in your desktop environment
  4. The behavior of the sudo command is not identical on all the systems and can be configured through visudo command, please check out sudoers(5) manpage for more info.
share|improve this answer
seems a much better explanation than the one that's getting all the votes. more thorough, more correct. even the OP replied "is that all?" to the answer that got all the votes. – johny why May 25 '15 at 17:16

Using regular sudo to run graphical programmes will on a rare occasion mess up permissions on some files. To be safe gksudo (or kdesudo as appropriate) should be used for running programmes with a GUI. I think this is a bug really, although I heard explanations that gksudo understands X server variables and sudo does not possibly leading to problems. Just as a tip; if you are running graphical programmes as root, instead of opening up one terminal for each programme you want to run, type ALT-F2 (alt and function key 2 at the same time), then type in the dialogue box that pops up "gksudo programme" without the quotes and programme replaced by the application you want to run.

share|improve this answer

sudo runs as the current user with elevated privileges. This has the potential of changing file permissions of certain user config files (relating to your graphical environment) when running graphical apps. You may find errors occurring when running these apps again without sudo.

gksudo (kdesudo under KDE) runs the apps as root user thus any file permissions touched are on root's files, not the users files. running these apps again without gksudo/kdesudo will always have the expected behavior.

share|improve this answer

The current answer is incorrect. According to the Ubuntu RootSudo wiki:

"You should never use normal sudo to start graphical applications as root. You should use gksudo (kdesudo on Kubuntu) to run such programs. gksudo sets HOME=~root, and copies .Xauthority to a tmp directory. This prevents files in your home directory becoming owned by root. (AFAICT, this is all that's special about the environment of the started process with gksudo vs. sudo)."

share|improve this answer
There are four other answers; which one is incorrect? Isn't your answer essentially the same as the one by Davros? – fixer1234 Apr 17 '15 at 6:30
I was referring to the answer marked as correct. Yes, Davros is saying the same thing, but I added this because his did not contain a link to a source. – eugene1832 Apr 17 '15 at 16:42
A better solution would be to propose an edit to that answer. Improving an answer is likely to be accepted (+2 rep), whereas essentially duplicating an answer is likely to attract downvotes. – fixer1234 Apr 17 '15 at 16:49

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.