28

Is the difference between sudo cmd and gksu cmd, the same as the difference
between starting a shell with sudo -i and sudo -s?

... or put another way,
Is sudo cmd the same as sudo -i cmd
and gksu cmd the same as sudo -s cmd?

EDIT: Based on what I read on an Ubuntu Documentation Page where it says:

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).

The "AFAICT" doen't really give me full confidence that there is nothing more to it.


(..a belated UPDATE: I tested his commemnt today (2 months later) about:
"This prevents files in your home directory becoming owned by root."
All files I created via sudo/gksu were all owned by "root", and the group was "root".)


I've read parts of the info sudo and noticed the -i and -s seem to be doing the same thing as the AFAICT environment issue...
but I hit overload.. so I've asked my question here.

PS.. My question is not about sudo vs gksu
.. It is more about: Is gksu the same as sudo -s
.. and if not, how do they differ?

4 Answers 4

18

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.

4
  • 1
    I don't know what you could mean by a graphical frontend ... a GTK app runs quite happily regardless of whether it is started via sudo or gksu... but it does run the progam in a different environment... (I'll add some more to my question to point out why I've asked the question...
    – Peter.O
    Nov 6, 2010 at 21:40
  • 2
    I've finally understood what you mean by a graphical frontend. I always use the terminal to run sudo/gksu... but in the spirit of brute-force trying everything I could think of, I tried running sudo and gksu via Alt+F2... Bingo! .. sudo disappeared into the void, but gksu rose to the occasion and presented me with the (legendary) graphical forntend ... It is the same dialog as that which appears for Synaptic Package Manager etc...
    – Peter.O
    Nov 7, 2010 at 0:55
  • PS.. I just tried gksu in a fresh terminal.. The password dialog pops up there, too... I must have seen it before but associated with the password (only), and not the fact that it was a GUI dialog from a Terminal command... ("I see". said the blind man :) ... Thanks...
    – Peter.O
    Nov 7, 2010 at 1:12
  • . following up further, spurred on by your answer, it seems that gksu changes the XAUTHORITY folder, and sudo does not... I'm not sure what that's all about, but it seem significant!... This has solved my dilema... (details in my answer below)
    – Peter.O
    Nov 7, 2010 at 5:08
11

sudo -i resets the login environment to the target user (root, in this case). Mainly, it is that the HOME environment variable is changed, which means the target user's ~/.bashrc is loaded.

gksu is, therefore, like sudo -i in that is switches $HOME to the root user.

1
  • Thanks KC.. It is starting to make sense to me (slowy, slowly) ... but it seems clear that gksu, by creating a copy of XAUTHORITY, and working from(?) it, puts gksu into a category quite seperate form any of the sudo variants which I've referred to... and realizing this has been the Aha! moment for me... The upshot is: Use gksu for GUI apps! .. but I am left with one more unresolved quandry... Does gksu only apply to GTK apps, or is it perfectly fine to use gksu when running a KDE GUI app?
    – Peter.O
    Nov 7, 2010 at 6:53
5

This isn't really an answer, but it may be of some interest...
I'm starting to get an idea of what goes on with these su commands,
but I'm not quite there yet... I do use gksu... This is more a journey of understanding for me... and I wan't to understand if gksu is valid for konsole or kate, or must I use the KDE variant kdesu..

Here are some results of some tests I've just tried.

From user fred's terminal, launch gnome-terminal

su style   resulting            custom   (ls)   new file
command    prompt               prompt   home   ownership
---------  -------------------- -------  -----  ----------
sudo      .root@DT:~#           fred's   fred   root
gksu       root@DT:/home/fred#  root's   fred   root
sudo -i    root@DT:~#           root's   root   root
sudo -s   .root@DT:~#           fred's   fred   root

These results don't agree with the Ubuntu Documentation Page, where it says:

 This prevents files in your home directory becoming owned by root

UPDATE: The XAUTHORITY env variables for the sudo and gksu invoked Terminals are different (as mentioned on the Ubuntu Documentation Page) ..

sudo    #### XAUTHORITY=/var/run/gdm/auth-for-fred-RsngLK/database
sudo -i #### XAUTHORITY=/var/run/gdm/auth-for-fred-RsngLK/database
sudo -s #### XAUTHORITY=/var/run/gdm/auth-for-fred-RsngLK/database
gksu    #### XAUTHORITY=/tmp/libgksu-xR2OGn/.Xauthority   

This shows that gksu is definitely not the same as the sudo -s command I referred to in the question ... and therefore anwers my otiginal question (in some still obscure way) ... and Chris's answer certainly got me thinking hard on this one! ... I need a coffee!!

3

sudo is for command line apps, gksu/gksudo for graphical ones

1
  • Thanks, my question may have been as unclear as my original understanding of the issue... I was primarily trying to find out What the specific difference was that made it necessary to have both commande.. It seems that the main difference is in the way that gksu works from a temporary copy of XAUTHORITY.. I'm not clear on the details of why XAUTHORITY needs to be handled specially, but is a major thing which distinguishes its behaviour from sudo
    – Peter.O
    Nov 7, 2010 at 6:42

You must log in to answer this question.

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