sudo vs gksudo. difference?
What's difference between sudo
and gksudo
?
Solution 1:
sudo
asks for the password on the command line, and gksudo
pops up a dialog box for it.
Solution 2:
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):
- Although both commands are indeed represents
sudo
, the UI used is NOT the only difference of the two commands. - 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 thesudo
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. - You still can use
sudo
command to launch GUI apps as root (for viewing apps' console output as an example), however you need to handleHOME
(and others such asXAUTHORITY
,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 usingsudo
-
sudo -H <rest of the command>
- (from
sudo
section 8 manual page) The-H ( HOME )
option requests that the security policy set theHOME
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
- (from
-
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
-
- The behavior of the
sudo
command is not identical on all the systems and can be configured throughvisudo
command, please check outsudoers(5)
manpage for more info.
Solution 3:
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.
Solution 4:
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.