Simple encrypted Linux folders with TAR and GPG

What’s the simplest way of encrypting a folder in Linux? Combining tar with gpg, it seems.

Let’s say you have some files in a folder called secret_files. To encrypt them you can run:

tar cvzf - secret_files/ | gpg -c > secret_files.tar.gz.gpg

This creates a compressed (with gzip) TAR archive [1] of your files, which is then symmetrically encrypted by GPG. I advise to create and store the passphrase you’ll be asked for with a password manager like KeePassXC.

To decrypt the files run:

gpg -d secret_files.tar.gz.gpg | tar xvzf -

What do you need this for?

You can use that for whatever you need encrypted files for :)

This isn’t a trick that I’ll start using often, but it may come in handy on some occasions, like sending private files through third parties, when I don’t even want the file names to leak. Password-protected ZIPs still present the filenames for example (see unzip -l password_protected.zip).

Sources

Just for the record, these are the URLs I got (and used) when I was “researching” [2] the topic of encrypting folders on Linux:

Footnotes

Comments

comments powered by Disqus