如何强制 GPG 使用控制台模式 pinentry 来提示输入密码?

ccp*_*zza 97 linux ssh terminal console gnupg

在基于控制台的环境(例如 ssh 会话)中使用 gpg 会失败,因为 GTK pinentry 对话框无法在 SSH 会话中显示。

我试过了,unset DISPLAY但没有帮助。GPG 命令行选项不包括用于强制 pinentry 进入控制台模式的开关。

较旧的 GPG 版本提供了基于文本的提示,该提示在 SSH 会话中运行良好,但升级后却失败了。

--textmode命令行开关,但显然,它还有其他作用。

为远程会话获取纯文本 pin 条目的正确和干净的方法是什么?

use*_*686 115

要永久更改 pinentry,请将以下内容附加到您的~/.gnupg/gpg-agent.conf:

pinentry-program /usr/bin/pinentry-tty
Run Code Online (Sandbox Code Playgroud)

(在缺少 pinentry-tty 的旧版本中,将 pinentry-curses 用于“完整终端”对话窗口。)

告诉 GPG 代理重新加载配置:

gpg-connect-agent reloadagent /bye
Run Code Online (Sandbox Code Playgroud)

  • 这并不完全“理智”。通常,`gpg-agent` 应该自己检测`$DISPLAY` 的存在或缺失,并选择合适的 pinentry... (11认同)
  • 该代理很可能能够检测到正在运行的 xorg 的存在。但是定义了“DISPLAY”并不一定意味着我可以或想要使用它,例如,当通过 SSH 连接时。 (8认同)
  • @lfxgroove:问题是`su` 不会改变你的TTY 的所有权,所以你需要手动`chown` 它。参见[这篇文章](https://wiki.archlinux.org/index.php/GnuPG#su)。 (4认同)
  • 另一个提示:要查看所有可用选项,请键入 `ls /usr/bin | grep pinentry`。我看到了`pinentry`、`pinentry-curses`、`pinentry-emacs`、`pinentry-gnome3`、`pinentry-gtk2`、`pinentry-qt`和`pinentry-tty`。这样你就可以选择更适合你的,如果你没有缺少`$DISPLAY` 的问题。 (4认同)
  • @Starx:你创造了一个。 (2认同)
  • 我必须将 `export GPG_TTY=$(tty)` 添加到我的 `~/.bashrc` 才能使其正常工作 (2认同)

Joh*_*den 15

在 debian 机器上:

sudo apt install pinentry-tty
sudo update-alternatives --config pinentry
Run Code Online (Sandbox Code Playgroud)

(并将其设置为 pinentry-tty)


rac*_*tup 10

我只是在 Ubuntu 16.04.3 上遇到了这个问题,当我尝试在没有密码的系统帐户上和通过 ssh 的用户帐户上使用 gpg2 (2.1.11) 生成/安装私钥时。没有任何工作给予:

gpg:密钥 FE17AE6D/FE17AE6D:发送给代理的错误:权限被拒绝
gpg:构建 skey 数组时出错:权限被拒绝

然后我发现对我有用,简而言之:

pico ~/.gnupg/gpg-agent.conf
# add: allow-loopback-pinentry
gpg-connect-agent reloadagent /bye
gpg2 --pinentry-mode loopback --import private.key
Run Code Online (Sandbox Code Playgroud)


Roc*_* W. 10

在 Ubuntu 18.04 上,默认安装 gpg 2.2.4,我有

/usr/bin/pinentry
/usr/bin/pinentry-gnome3
/usr/bin/pinentry-gtk-2
/usr/bin/pinentry-x11
Run Code Online (Sandbox Code Playgroud)

我能够执行以下操作以获得基于文本的 PIN 条目:

export GPG_TTY=$(tty)
gpg-connect-agent updatestartuptty /bye >/dev/null
Run Code Online (Sandbox Code Playgroud)

  • 这是正确的解决方案,也是来自 `man gpg-agent` 的官方解决方案,``` 您应该始终将以下行添加到 .bashrc 或用于所有 shell 调用的任何初始化文件中: GPG_TTY=$(tty) export GPG_TTY 重要的是,该环境变量始终反映 tty 命令的输出。```` (2认同)

小智 7

如果没有,请pinentry-curses使用 yum 或 apt-get安装。

然后,运行:

sudo update-alternatives --config pinentry

并从列表中选择 pinentry-curses。


mbl*_*the 6

我将从这里复制我的答案......

看着man pinentry-gnome3,我看到了这个:

   pinentry-gnome3  implements  a PIN entry dialog based on GNOME 3, which
   aims to follow the GNOME Human Interface Guidelines as closely as  pos?
   sible.   If the X Window System is not active then an alternative text-
   mode dialog will be used.  There are other flavors that  implement  PIN
   entry dialogs using other tool kits.
Run Code Online (Sandbox Code Playgroud)

不幸的是,这种文本模式回退对我不起作用。似乎其他人也有同样的 问题。然而,这条评论促使我尝试了一个不同的 GUI 引脚输入程序:pinentry-gtk2. 你可以这样切换:

> sudo update-alternatives --config pinentry
There are 3 choices for the alternative pinentry (providing /usr/bin/pinentry).

  Selection    Path                      Priority   Status
------------------------------------------------------------
* 0            /usr/bin/pinentry-gnome3   90        auto mode
  1            /usr/bin/pinentry-curses   50        manual mode
  2            /usr/bin/pinentry-gnome3   90        manual mode
  3            /usr/bin/pinentry-gtk-2    85        manual mode

Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/bin/pinentry-gtk-2 to provide /usr/bin/pinentry (pinentry) in manual mode
Run Code Online (Sandbox Code Playgroud)

一旦我切换,它对我来说非常有效!在桌面上的终端中,它将使用 GUI 密码条目,但是当我 ssh 进入我的机器时,它将使用文本模式密码条目。


Vic*_*ema 5

不确定这个问题最初是关于哪个版本的 GPG。我在 (K)ubuntu 20.04 LTS Focal 中使用 GPG v2.2.19。我所需要添加的只是--pinentry-mode loopback它开始在 TTY 中要求输入密码。我不需要安装任何东西。例如:

gpg --pinentry-mode loopback --export-secret-keys -a | less
Run Code Online (Sandbox Code Playgroud)