Possible Duplicate:
What is the difference between “gksudo nautilus” and “sudo nautilus”?

I have tiny script that I want it to run on start-up, but it needs sudo privileges so I use gksudo for the job. but it fails. (it works correctly using sudo.) Is there any difference between sudo and gksudo beside the inteface?

BTW: this is the tiny script I mentioned:


cat /sys/devices/platform/sony-laptop/kbd_backlight|if read state; then \
    echo $((1-$state)) | sudo tee /sys/devices/platform/sony-laptop/kbd_backlight; fi;
  • 1
    As you might have guessed, I'm total newbie! – Untitled Jul 15 '12 at 14:59
  • See this question askubuntu.com/q/11760/61218 – Anwar Jul 15 '12 at 15:04
  • Thank you. I've seen it. But I don't see how $HOME parameter affects my code. – Untitled Jul 15 '12 at 15:20
  • @fossfreedom I don't think this is an exact duplicate: this question has an issue similar to mine: my script fails with gksudo, but works with sudo, whereas the other does not involve scripts. I am not a total newbie, but I don't see how my script is affected by anything discussed in the other question. – sage Aug 6 '12 at 21:07
  • comment by user azernik in invalid answer below should be the accepted answer – Miguel Mota May 12 '17 at 21:59

The main difference is as follows :

gksudo : is used to run graphical (GUI) applications as root
sudo : is used to run command line applications as root

The reason your script won't work with gksudo is because you can't run a GUI without X running.

| improve this answer | |
  • 11
    And why? I'm a typical dumb user and saw that typing "sudo" is just enough to run even graphical applications with root rights. So I use sudo and save two letters of typing. Except if you can convince me why I should type two more letters ;) – Ray Jan 27 '15 at 10:30
  • 31
    Because the answer is wrong. gksudo is used to pop up the password prompt in a GUI window, no matter whether the application is GUI or CLI. sudo, similarly, asks for the password at the terminal instead of in a GUI window, regardless of the type of application being run. Sometimes, in scripts that don't run in an interactive terminal, gksu is the easiest way to get a user-entered password straight to sudo. – azernik May 28 '15 at 22:59
  • 5
    why so many votes on a wrong answer.... – Krypton Jan 26 '17 at 18:40
  • 2
    because down-vote costs reputation :) – HongboZhu Mar 9 '17 at 11:06
  • xenial was last LTS with the gksu package containing gksudo and gksu. For historical interest, one thing I think it may have done differently is not to change certain gui/gnome files in places like ~/.gtk3 to root ownership. – Jack Wasey Mar 21 at 9:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.