I have a gpg .key file that is used as passphrase for decrypting a .dat.pgp file. The encrypted .data.pgp file gets successfully decrypted on one server with same .key file using following command
cat xxx_gpg.key | /usr/bin/gpg --batch --quiet -o xxx.dat --passphrase-fd O -d xxx.dat.pgp
But, when I move same key to another server xxx_gpg.key and run same above command, I get following error -
gpg: decryption failed: No secret key
EDIT:
I find that gpg --list-secret-keys
returns some data on server where it works but no results are returned for other server.
How can we configure secret key
To see, run the PGP message in the question through any base64 decoder (e.g., some online one). Because the message isn't encrypted but instead only signed, then no key is needed to decrypt it. It's just a signature and some text wrapped up together. So GPG unwraps it without needing a key.
The GPG key pair comprises two types of keys: Private and Public keys. The private GPG keys are encrypted and stored in the secret keyring, and public keys are maintained with certificates attesting to their trustworthiness in the public keyring.
To decrypt a message the option --decrypt is used. You need the private key to which the message was encrypted. Similar to the encryption process, the document to decrypt is input, and the decrypted result is output. blake% gpg --output doc --decrypt doc.
I just ran into this issue, on the gpg CLI in Arch Linux. I needed to kill the existing "gpg-agent" process, then everything was back to normal ( a new gpg-agent should auto-launch when you invoke the gpg command, again; ...).
gpg-agent
in a terminal and/or reboot ...Looks like the secret key isn't on the other machine, so even with the right passphrase (read from a file) it wouldn't work.
These options should work, to
A few useful looking options from man gpg
:
--export
Either export all keys from all keyrings (default keyrings and those registered via option--keyring
), or if at least one name is given, those of the given name. The new keyring is written to STDOUT or to the file given with option--output
. Use together with--armor
to mail those keys.
--export-secret-keys
Same as--export
, but exports the secret keys instead.
--import
--fast-import
Import/merge keys. This adds the given keys to the keyring. The fast version is currently just a synonym.
And maybe
--keyring file
Add file to the current list of keyrings. If file begins with a tilde and a slash, these are replaced by the $HOME directory. If the file‐ name does not contain a slash, it is assumed to be in the GnuPG home directory ("~/.gnupg" if --homedir or $GNUPGHOME is not used).Note that this adds a keyring to the current list. If the intent is to use the specified keyring alone, use
--keyring
along with--no-default-keyring
.
--secret-keyring file
Same as--keyring
but for the secret keyrings.
I was trying to use aws-vault which uses pass and gnugp2 (gpg2). I'm on Ubuntu 20.04 running in WSL2.
I tried all the solutions above, and eventually, I had to do one more thing -
$ rm ~/.gnupg/S.* # remove cache
$ gpg-connect-agent reloadagent /bye # restart gpg agent
$ export GPG_TTY=$(tty) # prompt for password
# ^ This last line should be added to your ~/.bashrc file
The source of this solution is from some blog-post in Japanese, luckily there's Google Translate :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With