GPG2 Encryption - No public key error

8,323

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.

Share:
8,323

Related videos on Youtube

Steve Ward
Author by

Steve Ward

Code monkey trying to pick up better ways of working ... lots of head scratching and bananas.

Updated on September 18, 2022

Comments

  • Steve Ward
    Steve Ward over 1 year

    When I generate my keys using

    gpg2 --gen-key
    

    and then I try to try to encrypt the file using

    gpg2 --batch --yes -r [email protected] --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?

  • Steve Ward
    Steve Ward almost 8 years
    Thank you for this - it does work when I remove the home directory parameter. Thats awesome. The reason the parameter value of . was there was so that the files pubring.gpg etc. were checked in to source control in that directory (the gnupg folder is not). I'm wondering if there is a way of using a home directory param of . I suppose I could manualy copy those files (pubring.gpg etc) from gnupg to my folder so I can check in to source control..
  • Jens Erat
    Jens Erat almost 8 years
    The ~/.gnupg folder is hidden by default. Enable hidden files to be displayed, or use ls -a to view it using a terminal. If you had another folder before, you must have changed environment variables or other configuration; ~/.gnupg is the default for unixoid systems.