I recently needed to store an exported password list from my browser locally, but I wanted to ensure that it would still be safe in the event that my machine gets compromised with a virus or something of the sort.

I looked up how to do this on Ubuntu and found a nice guide from DigitalOcean to using GPG, or GNU Privacy Guard. It's a public key encryption tool, and I found that using it was pretty simple.

After installing GPG, you can first generate your keys:

gpg --gen-key

And it'll guide you through the process, which ends with you providing a passphrase. Afterwards, you should probably generate a revocation certificate in case you ever want to invalidate these keys. Always keep these keys safe.

In order to encrypt your files, all you need to do is:

gpg --encrypt -r <your-email> <your-file>

Where -r stands for recipient and marks your public key to be used in encrypting the file.

Decrypting it is just a matter of doing:

gpg <your-file>

After which you'll be prompted to enter your passphrase.

To view the entire guide and learn how to verify and sign keys, among other things, visit this page. Alternatively, read this nifty guide from Brendan Kidwell.