Taken from here:
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.
Please note that this is primarily about configuration files. If you run Nautilus as root
, even with gksu
/gksudo
, and you create a file or folder anywhere with it (including in your home directory), that file or folder will be owned by root
. But if you run Nautilus (or most other graphical applications) as root
with sudo
, they may save their configuration files in your home directory (rather than root
's home directory). Those configuration files may be owned by root
and inaccessible when you're not running as root, which can severely mess up your settings, and may even keep some applications from working altogether.
The solution, once you have made this mistake, is to find the configuration files and delete them or chown
them back to belonging your non-root
user. Many such files start with a .
or are contained in a directory that starts with a .
. Some are located inside the .config
folder in your home directory. To see files and folders that start with a .
in Nautilus, press Ctrl+H (this shows hidden files.) To see them with ls
, use the -a
(or -A
) flag.
To find if there are files not owned by you in your home directory, you can use the following command in a terminal:
find $HOME -not -user $USER -exec ls -lad {} \;
which will list all files under the home directory not owned by the user.
gksu
is basically a graphical frontend for sudo that allows graphical command to be run without the need to run an X terminal emulator and using su directly. It's effectively just a GTK+ skin for the superuser commands.
So if you wanted to run a GUI based program as root, you would invoke it with gksu cmd
, rather than sudo cmd
, which is used for invoking console programs as root.
Best Answer
Both files point to the same place:
...
gksudo
is symlinked togksu
. But this doesn't mean they do the same things, far from it.Applications can detect the command used to run it. This is typically
argv[0]
in C-style languages or$0
in Bourne-style shell scripts. The application can look at that and in this case, actually it changes how it works. The first indication of this is in theman gksu
page:If you look in the source (
apt-get source gksu
) forrun_mode
, you'll see how it detects this:You can override this with the
--su-mode
/-w
and--sudo-mode
/-S
arguments (so you can run equivalent commands without needing thegksudo
symlink... But that's up to you.If you want to know how these "modes" really differ, there's only a bit of escaping in
gksu
. You need to follow it intolibgksu
. This is the library that actually checks permissions before handing off to the system.If no mode is specified (eg you call
gksu
without arguments) by the time it reacheslibgksu
, it will check Gconf (as Stefano points out) and if it still can't decide, it'll default to thesu
mode.