Summary: when you want to do this, use the --symmetric
option when encrypting.
Let's look at the details of what's really going on here; a little understanding often helps when trying to do things right.
When you encrypt a file using GnuPG, it uses "symmetric" encryption. That is to say, it uses a single key that will both encrypt the plaintext and decrypt the cyphertext. Why does it do this? Becuase the symmetric algorithms are much faster than the public/private key algorithms (where separate keys are used to encrypt and decrypt), and for other reasons we'll see later.
Where does it get this key it uses to encrypt the file? It makes up a random one. No, I'm not kidding you here.
Now at this point you might think we have a little issue. The file's encrypted with a random key, and nobody (except that particular GnuPG process) knows what it is. So what happens next?
Here's the trick: that random key is then encrypted with other keys, and stored in the file. This is how we allow multiple users to be able to decrypt the file. For example, the backups at my company are encrypted so that both I and my business partner can decrypt them: GnuPG encrypts the file encryption key with my public key and again with my partner's public key, and stores both of these with the encrypted data; now I, using my private key, can decrypt the copy encrypted with my public key (or he can do the same with his copy), retrieve the symmetric key used to encrypt the data, and decrypt it.
So what does --symmetric
do? It just encrypts that random encryption key with a symmetric algorithm itself, this time using a key based on the supplied passphrase. Now anybody who knows the passphrase can also decrypt the file.
That's nice for on file, but this soon enough becomes inconvenient when you've got many files, encrypted with different passphrases so that different groups of people can get access to them, which is one reason why we usually use the public key systems instead.
But now you've learned, the hard way unfortunately, a very valuable lesson: your private key is important! If you lose that, you lose access to anything anybody's ever encrypted using your public key. Generate it once, keep it safe, and keep it backed up in several places.
What you wanted to do was was to add the --symmetric
option to allow decrypting the file with just a passphrase.
The problem was that you encrypted the file with your public key, and when you do that, you need your secret key (stored in ~/.gnupg
) to decrypt it.