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

1

7

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

gpg --export-secret-keys [email protected]

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

  • an argument --passphrase 'my-passhrase'
  • from stdin echo 'my-passphrase' | gpg ...

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

Turncoat answered 30/12, 2021 at 16:16 Comment(0)
M
7

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

Mt answered 4/1, 2022 at 12:36 Comment(5)
The more I discover gpg's CLI options, the more I think people behind it take drugs.Jerrylee
Actually not, they are quite kind and nice people. It's just security which sometimes requires weird steps and solutions.Mt
I was of course kidding. What I meant is: every time I needed an "advanced" usage of the gpg binary, it had options to fit my needs. But every time the involved options was not intuitive to use at all. Exactly as in your answer here: it's not intuitive at all, but it do exactly what's neededJerrylee
Sadly, this answer spits out multiple errors for me and doesn't work. Like this one: gpg: keyblock resource '/home/user/.gpg/pubring.kbx': No such file or directoryTympanites
And do you actually have that .kbx file?Mt

© 2022 - 2025 — McMap. All rights reserved.