I haven’t used my Linux Mint maya for about half year. Today I logged in, did a system update with the following command:
sudo apt-get update sudo apt-get dist-upgrade sudo reboot
Then when I logged in again and tried to remove the old kernels with the Package Manager, it just died after prompting me for the password, without saying a word. That’s quite rude. I tried other application that may require root privilege like Login Window and Update Manager, they won’t start too!
So, what’s the problem? Why they all didn’t work? I need to get more diagnostic message.
First, find out what command will be executed when we click the Package Manager menu
ps -ejfH | grep [s]ynaptic
curu 6285 4070 4055 4055 2 23:01 ? 00:00:00 gksu /usr/sbin/synaptic root 6286 6285 6286 6286 0 23:01 ? 00:00:00 /usr/bin/sudo -H -S -p GNOME_SUDO_PASS -u root -- /usr/sbin/synaptic
Now that we got the final command, run it with debug on:
gksu -d /usr/sbin/synaptic
xauth: /tmp/libgksu-paLvKO/.Xauthority STARTUP_ID: gksu/|usr|sbin|synaptic/23259-0-linuxplayer_TIME13218554 cmd: /usr/bin/sudo cmd: -H cmd: -S cmd: -p cmd: GNOME_SUDO_PASS cmd: -u cmd: root cmd: -- cmd: /usr/sbin/synaptic buffer: -GNOME_SUDO_PASS- brute force GNOME_SUDO_PASS ended... Yeah, we're in... xauth: /tmp/libgksu-paLvKO/.Xauthority xauth_env: /home/curu/.Xauthority dir: /tmp/libgksu-paLvKO
From the output, we know that gksu setup xauth thing, then start synaptic with sudo. I am sure that the sudo privilege is OK, so why couldn’t gksu start synaptic? Forget it! Why not just start a very very simple X application to test?
We can show a simple dialog box with this command
zenity --info --text test
Create the script /tmp/t.sh:
#!/bin/bash set > /tmp/test.log zenity --info --text test
Run with gksu
gksu -d /tmp/t.sh
No ask_pass set, using default! xauth: /tmp/libgksu-ownhJm/.Xauthority STARTUP_ID: gksu/|tmp|t.sh/23501-0-linuxplayer_TIME14345711 cmd: /usr/bin/sudo cmd: -H cmd: -S cmd: -p cmd: GNOME_SUDO_PASS cmd: -u cmd: root cmd: -- cmd: /tmp/t.sh buffer: -GNOME_SUDO_PASS- brute force GNOME_SUDO_PASS ended... Yeah, we're in... xauth: /tmp/libgksu-ownhJm/.Xauthority xauth_env: /home/curu/.Xauthority dir: /tmp/libgksu-ownhJm
What’s the shit! that simple dialog box didn’t show too! check the log file /tmp/test.log where I put the environment variables. To my suprise, the DISPLAY variable was not set! For any X graphic application, if there’s no DISPLAY(DISPLAY environment variable not set), there will be no display.
So, where has the $DISPLAY variable gone? The X terminal must have set it, we can verify that:
curu@linuxplayer ~ $ echo $DISPLAY :0 curu@linuxplayer ~ $
I know that sudo may clear some environment variable, take a look at the sudoers file:
Defaults env_reset Defaults env_keep = "http_proxy https_proxy ftp_proxy"
Well, seems the $DISPLAY variable was not kept after sudo, let me add it
Defaults env_keep = "http_proxy https_proxy ftp_proxy DISPLAY"
Run gksu again, the dialog appears like a magic! And all other broken graphic application that require root privilege worked too!
gksu can run in two different Authentication mode, su and sudo, we can change the behavior with the gksu-properties command. If the mode is set to “sudo“, whenever you call gksu to run a command, it will run it with sudo by default, and you need to edit sudoers file to keep the $DISPLAY environment variable.
There are two ways to run application as another user in gnome desktop environment, gksu vs pkexec . In fact, there are two menu to run Package Manager on maya mate, the one in the System category use gksu whereas the one in the Administration category use pkexec, so you may find that the latter if OK when the former is broken. pkexec use polkit and the default configuration works well.