22 March 2014

An alternative to gksudo/kdesudo

The gksudo and kdesudo commands are okay, if we whether work in GNOME or KDE environments, or are satisfied with the number of required dependencies. However, these pacakges are pretty cumbersome, if we want just a lightweight GUI version of sudo, especially on non-GTK/non-KDE environments like Xfce. In this post I'll show a simple GUI front-end I use on my Xfce setup. Steps:
  • Install x11-ssh-askpass or similar.
  • Create ~/bin/xsudo executable with the following contents:
    #!/bin/bash -
    sudo -A $@
  • Set the $SUDO_ASKPASS environment variable in some initialization script (e.g. ~/.xinitrc, ~/.bash_profile, ~/.bashrc etc.):
    export SUDO_ASKPASS="/usr/bin/x11-ssh-askpass"
    Alternatively, put the following into /etc/sudo.conf file:
    Path askpass /usr/bin/x11-ssh-askpass
    (Make sure to adjust the path.)
Now we can use xsudo command just as if it were gksudo or kdesudo.