What is the difference between gksudo and gksu?

Is there any difference between the behavior of gksu foo and gksudo foo?
Can they be used interchangeably?


Both files point to the same place:

$ ls -l /usr/bin/gksudo 
lrwxrwxrwx 1 root root 4 2010-09-27 18:23 /usr/bin/gksudo -> gksu

... gksudo is symlinked to gksu. 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 the man gksu page:

gksu  is  a  frontend  to  su  and gksudo is a frontend to sudo.

If you look in the source (apt-get source gksu) for run_mode, you'll see how it detects this:

  { /* support gksu_sudo_run */
    gchar *myname = g_path_get_basename (argv[0]);
    if (!strcmp(myname, "gksudo"))
      run_mode = SUDO_MODE;
    g_free (myname);
  }

You can override this with the --su-mode/-w and --sudo-mode/-S arguments (so you can run equivalent commands without needing the gksudo 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 into libgksu. 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 reaches libgksu, it will check Gconf (as Stefano points out) and if it still can't decide, it'll default to the su mode.


In Ubuntu (!), there is no difference.

  • gksu would normally log in the root user and run an app on this session. However, on Ubuntu, it defaults to using the "sudo mode", which is equivalent of running gksudo. This is because on ubuntu, you can't log in as root by default.

  • gksudo is the graphical equivalent of sudo (and as Oli points out, just a symbolic link to gksu)

From the gconf entry of gksu:

alt text

Furthermore, on the difference between sudo and gksudo:

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).
 — (from the community documentation via Chris Wilson)


I know that this is an old thread, but I've been asked to tell you about a subtle but essential difference between gksu and gksudo.

Although I have looked long and hard, I cannot find a documented difference anywhere, and yet it does exist. I have also not found out why there is a difference. I found this the hard way when I accidentally deleted some system files precisely because of this difference (discussed in a thread in Ubuntu Forums) — I had been using gksu, but since then I have made sure always to use gksudo.

To summarise, try this.

  1. Create three files in some folder:
    touch abc
    touch abc.tmp
    touch abctmp
  2. Run the following six commands. The first five give the same (expected) result (i.e. just abc.tmp) whereas the sixth includes an extra file (abctmp) that it shouldn't.

    find . -regextype posix-egrep -regex '.*\.tmp' -print
    sudo find . -regextype posix-egrep -regex '.*\.tmp' -print
    gksudo -- find . -regextype posix-egrep -regex '.*\.tmp' -print
    gksudo --su-mode -- find . -regextype posix-egrep -regex '.*\.tmp' -print
    gksu --sudo-mode -- find . -regextype posix-egrep -regex '.*\.tmp' -print
    gksu -- find . -regextype posix-egrep -regex '.*\.tmp' -print
    

Imagine the problems when you replace -print with -delete in the find command (which is exactly what happened to me, causing some system files to be deleted).

So, please use gksudo instead of gksu.