2

enter image description here

How can I trigger above dialog from a shell script which needs to prompt for a password?

I already encountered and use zenity for that purpose, though I like the former more for aesthetic reasons (yeah, that matters sometimes ;-) .

Zenity alternative:

enter image description here

zenity --password --title="Enter private passphrase"

Ubuntu 20.04, GTK, GNOME

4
  • You want to set different password with first image??
    – PRATAP
    Aug 22, 2020 at 10:14
  • 1
    not sure but it looks like pkexec (polkit)
    – user986805
    Aug 22, 2020 at 10:35
  • @UnKNOWn no, it is a prompt to run something with higher privileges/different user.
    – bela53
    Aug 22, 2020 at 12:07
  • @bac0n I think that's it, thanks! If you want, you can post it as an answer and I will accept it.
    – bela53
    Aug 22, 2020 at 12:07

2 Answers 2

1

I know this post is nearly 6 months old but nobody has suggested using the yad (yet another dialogue) tool. This is how it looks:

yad screenshot

The full command is:

password="$(yad --center --width=300 --image=keys.png --entry --hide-text --button=gtk-ok:0 --button=gtk-cancel:1 --title="Authentication required" --text="Enter password:")"

The password is not displayed on the screen as it is entered (the "--hide-text" does that). The buttons are the standard gtk "OK" and "Cancel" ones. In this example the password that was entered can be accessed from the variable $password, e.g.

echo $password

If the cancel button is pressed the return code ($?) from yad is 1 (from --button=gtk-cancel:1) and the return code is 0 when the OK button is pressed (from --button=gtk-ok:0).

yad can be intalled in later Ubuntu versions from the Software Centre, 16.04 requires installation using:

sudo apt install yad

The home page for yad is here: https://sourceforge.net/projects/yad-dialog/

Other examples showing how to use yad can be found here: https://sourceforge.net/p/yad-dialog/wiki/browse_pages/

0

I think that the corrent solution would be to use pinentry-gnome3. IIRC, it is a dependency of gpg

askpass() {
    prompt=$1
    echo -e "SETPROMPT $prompt\nGETPIN\nBYE" | pinentry-gnome3 | grep -E '^D ' | sed 's/D //'
}

password=$(askpass 'Enter your password:')

You must log in to answer this question.

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