Can I enter my gpg password just once and unlock all my sub keys (signing, decryption, authentication)?
At the moment, I need to enter my gpg password three times (for signing, for decryption, for authentication). This is inconvenient.
I tried to come up with a shell script.
#!/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"
But unfortunately, that way passwords gnupg-agent doesn't cache the password. Can this be fixed?
System information:
- When not using that shell script, I have no issues with gnupg-agent. When I manually sign / decrypt a file in shell, pinentry asks for password twice, then caches it until reboot.
- Using Debian Wheezy.
- gpg version:
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)
I've asked on gnupg-users mailing list a while ago, but no reply.
Perhaps this answer would work? Perhaps gpg-connect-agent
is required?
exec 3<<<"$passphrase"
was new even to me... And I just threw a 250 rep bounty at the answer you quote.