I use Trisquel GNU/Linux with GNOME Flashback Desktop Environment. I need a GUI password prompt for user for executing command with sudo in script. Example consider following script:

zenity --question --text="Do you want to install this package?"
if [[ $? -eq 0 ]]; then sudo apt-get install package
else zenity --warning

Which is to be executed following way (Run) i.e not inside terminal:


So, It is needed to ask for password in order to run command with sudo otherwise it fails to do a job.

Therefore, How do I ask password by GUI prompt?


You can ask password by means of GUI prompt with the help of -A, --askpass options for sudo.

From the sudo manpage:

-A, --askpass
                 Normally, if sudo requires a password, it will read it from the user's terminal.  If the -A
                 (askpass) option is specified, a (possibly graphical) helper program is executed to read the user's
                 password and output the password to the standard output.  If the SUDO_ASKPASS environment variable
                 is set, it specifies the path to the helper program.  Otherwise, if sudo.conf(5) contains a line
                 specifying the askpass program, that value will be used.  For example:

                     # Path to askpass helper program
                     Path askpass /usr/X11R6/bin/ssh-askpass

                 If no askpass program is available, sudo will exit with an error.

So, you can graphical helper program such as ssh-askpass which prompts a user for a pass-phrase using GNOME:

$ which ssh-askpass

So, Add the following line to /etc/sudo.conf:

# Path to askpass helper program
Path askpass /usr/bin/ssh-askpass

And you will find GUI password prompt:


You can also user other program like zenity for that. Example I use following:

$ cat /etc/sudo.conf
# Path to askpass helper program
Path askpass /usr/local/bin/zenity_passphrase

Where zenity_passphrase is a custom script set to be used directly as command:

$ cat $(which zenity_passphrase)
zenity --password --title="sudo password prompt" --timeout=10

Which works like:



  • You can also use gksudo (GTK+ frontend for su and sudo) instead of sudo in the script which asks with GUI prompt (gksu and gksudo are obsolete and abandoned in 2019-2020):


  • You can also use pkexec (polkit application) with some (for others it needs to be configure) applications/commands:


  • When using pkexec, for example pkexec leafpad, it gives Cannot open display: after entering the password. Is there any aditional configuration needed?
    Dec 13 '17 at 3:13
  • Try DISPLAY=:0 pkexec leafpad
    – Pandya
    Dec 13 '17 at 3:19
  • Still not working, the same message Cannot open display: appears
    Dec 14 '17 at 0:53
  • gksu and gksudo is dead, abandoned in 2019 or before that. Apr 29 '20 at 1:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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