一次缓存所有 gpg 子项密码?防止需要输入多个 gpg 密码?

adr*_*nos 11 shell-script gpg gpg-agent

我可以只输入一次我的 gpg 密码并解锁我的所有子密钥(签名、解密、身份验证)吗?

目前,我需要输入我的 gpg 密码三次(用于签名、解密、身份验证)。这很不方便。

我试图想出一个shell脚本。

#!/bin/bash
set -x
set -e
set +o history

signing_key=77BB3C48
encryption_key=CE998547

tempfile="$(mktemp)"
echo "test" > testfile

unset passphrase || exit 1
read -sp 'Enter password. ' passphrase ; echo

exec 3<<<"$passphrase"

gpg2 --no-tty --use-agent --batch --yes --passphrase-fd 3 --sign-with "$signing_key" --clearsign "$tempfile"
gpg2 --no-tty --use-agent --verify "$tempfile.asc"

gpg2 --no-tty --use-agent --yes --armor --recipient "$encryption_key" --encrypt "$tempfile"

exec 3<<<"$passphrase"
gpg2 --no-tty --use-agent --batch --decrypt --passphrase-fd 3 "$tempfile.asc"
Run Code Online (Sandbox Code Playgroud)

但不幸的是,这样密码 gnupg-agent 不会缓存密码。这可以解决吗?

系统信息:

  • 不使用该 shell 脚本时,我对 gnupg-agent 没有任何问题。当我在 shell 中手动签名/解密文件时,pinentry 要求输入密码两次,然后缓存它直到重新启动。
  • 使用 Debian Wheezy。
  • gpg 版本:

dpkg -l | grep gnupg

ii  gnupg                                        1.4.12-7+deb7u3                    i386         GNU privacy guard - a free PGP replacement
ii  gnupg-agent                                  2.0.22-3                           i386         GNU privacy guard - password agent
ii  gnupg-curl                                   1.4.12-7+deb7u3                    i386         GNU privacy guard - a free PGP replacement (cURL)
ii  gnupg2                                       2.0.22-3                           i386         GNU privacy guard - a free PGP replacement (new v2.x)
Run Code Online (Sandbox Code Playgroud)

不久前我在 gnupg-users 邮件列表上询问过,但没有回复。

也许这个答案会奏效?也许gpg-connect-agent是必需的?

Hau*_*ing 0

我做了一些调查,结果令我惊讶但很简单:

当以这种方式调用时,根本gpg无法进行通信!能够自行完成所有这些操作。gpg-agent gpg

但如果gpg-agent甚至不知道发生了什么事,那么它就很难知道以前不知道的密码。