I'm trying to encrypt our backups using GnuPG as a pipe (reading from stdin and writing to stdout). The passphrase is read from a file. An example command:
echo "mysecret" | gpg --passphrase-file password.key --batch --symmetric --cipher-algo AES256 > test.gpg
When I run this as a regular user, it works fine. But if I run it as root, I get:
gpg: gpg-agent is not available in this session gpg: can't query passphrase in batch mode gpg: error creating passphrase: invalid passphrase gpg: symmetric encryption of `[stdin]' failed: invalid passphrase
How can I get
--passphrase-file working for root?
I cannot use
--passphrase-fd 0 as suggested here because stdin is the data to be encrypted. I'm using GPG 1.4.20 (from Ubuntu 16.04.5 LTS)