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


I have a text file on my GNU/Linux laptop and I want to encrypt it with my GPG private key so I can decrypt it later and see the output. I've tried this:

gpg --encrypt file.txt

but I'm asked to provide Current recipients. I don't want any recipients, I want to read it myself.

How can I encrypt a file using GPG?

Best Answer

I have used this method to encrypt a file gpg -r -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)