59

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

Sid
  • 10,533
  • 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 https://askubuntu.com/questions/284306/why-is-gksu-no-longer-installed-by-default?noredirect=1&lq=1 ) – michael Nov 11 '21 at 10:03

3 Answers3

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.

Oli
  • 293,335
  • 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 '11 at 08: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 03 '11 at 09: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 02 '13 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 :) – Jacob Vlijm Aug 05 '14 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.

Paddy Landau
  • 4,548
  • 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 – Warren Hill Apr 30 '13 at 20:09
  • @WarrenHill — yes, in theory! But not in practice. I do not know why. – Paddy Landau May 01 '13 at 09:22
  • 2
    Interesting, and verified on 13.04. Definitely looks like a quote handling bug. – l0b0 Jun 02 '13 at 07:35
  • 4
    Filed a bug. – l0b0 Jun 02 '13 at 07:46
  • 1
    @l0b0 - thanks, I've added my vote to the bug. – Paddy Landau Jun 02 '13 at 12:15
  • The only one of those commands that gave me any output was the last one which printed ./abctmp... And yes, I did create the files correctly :-/ – Seth Mar 06 '14 at 20:52
  • @Seth, I have repeated the commands and I got the same results as always. I'm using 12.04; what version are you using? Did you cut-and-paste the commands correctly? Are you using Bash? Check the files /etc/profile, ~.profile and ~.bashrc for any changes that may affect the results. Otherwise I'm at a bit of a loss as to why you had an inconsistent result. – Paddy Landau Mar 07 '14 at 09:44