How to encrypt a file using my GPG private key so I can decrypt it later

I have used this method to encrypt a file gpg -r [email protected] -e ./filename and this will create filename.gpg which is the encrypted content.

And to decrypt you do gpg -d filename.gpg

In regards to the email requirement - when you generate a new key using gpg --gen-key you will be required to enter an email address and it will create a public/privatey key pair based on that email address. You simply need to use that same email address. It does not send it, it simply tell gpg which private/public key pair to use (and the identifier is the email address)


The canonical way is to use --encrypt-to name with your id (typical: mail address) for name. Documentation says that's the way to to "encrypt-to-self".


A better way is to encrypt using your PUBLIC key, then use your PRIVATE key later to decrypt the file. This way lends itself to automating encryption via a non-interactive script:

gpg --batch --yes --trust-model always -r $YOURGPGPUBKEYEMAIL -e ./file.txt

NOTE: I upload ONLY my PUBLIC key to public server I want to protect data on, keeping my PRIVATE key apart from it. That's pretty tight.

Obviously if you're NOT using your own public key, tread carefully with the --trust-model always switch.

Also be aware that decrypting will of course require a password unless you automate this too. HTH- Terrence Houlahan