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 不会缓存密码。这可以解决吗?
系统信息:
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
是必需的?
我做了一些调查,结果令我惊讶但很简单:
当以这种方式调用时,根本gpg
无法进行通信!能够自行完成所有这些操作。gpg-agent
gpg
但如果gpg-agent
甚至不知道发生了什么事,那么它就很难知道以前不知道的密码。