How to force GPG to use console-mode pinentry to prompt for passwords?
Using gpg from a console-based environment such as ssh sessions fails because the GTK pinentry dialog cannot be shown in a SSH session.
I tried unset DISPLAY
but it did not help. The GPG command line options do not include a switch for forcing the pinentry to console-mode.
Older GPG versions offered a text-based prompt that worked fine in SSH sessions but after the upgrade it just fails.
There is the --textmode
command line switch but apparently, it does something else.
What would be the proper and clean way of getting plain-text pin entry for remote sessions?
Solution 1:
To change the pinentry permanently, append the following to your ~/.gnupg/gpg-agent.conf
:
pinentry-program /usr/bin/pinentry-tty
(In older versions which lack pinentry-tty, use pinentry-curses for a 'full-terminal' dialog window.)
Tell the GPG agent to reload configuration:
gpg-connect-agent reloadagent /bye
Solution 2:
On a debian box:
sudo apt install pinentry-tty
sudo update-alternatives --config pinentry
(and set it to pinentry-tty)
Solution 3:
On Ubuntu 18.04, with the default installation of gpg 2.2.4, I have
/usr/bin/pinentry
/usr/bin/pinentry-gnome3
/usr/bin/pinentry-gtk-2
/usr/bin/pinentry-x11
I was able to do the following to have a text-based PIN entry:
export GPG_TTY=$(tty)
gpg-connect-agent updatestartuptty /bye >/dev/null