GPG2 Encryption - No public key error

When I generate my keys using

gpg2 --gen-key

and then I try to try to encrypt the file using

gpg2 --batch --yes -r --always-trust --homedir . -e test.text

I get an error "Encryption failed: No Public Key" error.

I can however see it using the command:

gpg2 --list-keys

Importing the public key explicitly doesn’t help. Ideas?

1 Answer

You're setting your current work directory as GnuPG home directory, which is pretty much never the thing you want to do. For day to day usage, do not set this option at all and have GnuPG use the default GnuPG home directory location (~/.gnupg).

Leave out this option, and encryption will work fine.

Additionally, --always-trust should never be used together with keys you did not validate on your own, ie. only together with the fingerprint or at least long key ID of the key. An attacker can generate keys for arbitrary other mail addresses/user IDs and distribute them, you might be ending up encrypting for the wrong key. There are reasons to use this flag (especially when interfacing GnuPG from scripts and applications), but be very sure about its implications regarding security.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like