59

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

1
  • nb: as of ubuntu 18.04, gksu/gksudo are deprecated (gone) and replaced by policykit (polkit), being that they were unsupported and unsecure, which is as of now (post-2018) what they have in common ;-) (see also askubuntu.com/questions/284306/… )
    – michael
    Nov 11, 2021 at 10:03

3 Answers 3

41

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.

4
  • 1
    To add to Oli's comment; Though gksudo is symlinked to gksu, In Ubuntu, by default we will only be using gksudo because we have the /apps/gksu/sudo-mode enabled. So unless someone forces the --su-mode option gksu is not used.
    – Vish
    Apr 24, 2011 at 8:50
  • 5
    @Oli: I wouldn't immediately conclude that there is no difference just because it's a symlink. Look at busybox, depending on the name of the symlink, different actions are performed. In this case, I don't know if it's true or not, but AFAIK it's indeed the case.
    – Lekensteyn
    Jul 3, 2011 at 9:31
  • 1
    -1, very misleading: software may behave differently depening on what name was used to invocate them. For example bash turns on POSIX strict mode when invoked as sh. And gksu is also aware of invocation name.
    – MestreLion
    May 2, 2013 at 18:53
  • Using internet on my cellphone with too small screen and too large fingers, I must have unintentionally downvoted. I upvoted to compensate :) Aug 5, 2014 at 12:44
38

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)

15

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.

7
  • Just tried this on 12.04LTS. Don't yet fully understand why but there is a difference. The source code for gksu shows that gksudo is equivalent to typing gksu --sudo-mode Apr 30, 2013 at 20:09
  • @WarrenHill — yes, in theory! But not in practice. I do not know why. May 1, 2013 at 9:22
  • 2
    Interesting, and verified on 13.04. Definitely looks like a quote handling bug.
    – l0b0
    Jun 2, 2013 at 7:35
  • 4
    Filed a bug.
    – l0b0
    Jun 2, 2013 at 7:46
  • 1
    @l0b0 - thanks, I've added my vote to the bug. Jun 2, 2013 at 12:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .