linuxgnupgpgp

Is it possible to export a GPG private key without passphrase being provided in a prompt?


I would like to automate a GPG private key export so it runs without user interaction.

gpg --export-secret-keys my@email.com

I tried providing --batch --passphrase-fd 0 arguments both with passphrase being passsed as:

It didn't work. Is it even possible to export private keys without user interaction?


Solution

  • You should add --pinentry-mode=loopback parameter, as well as --batch. Full example from the RNP CLI tests suite:

    gpg --batch --homedir .gpg --pinentry-mode=loopback --yes --passphrase "password" --output keyfile.asc --export-secret-key userid