Recipe 7.18 Encrypting Directories

7.18.1 Problem

You want to encrypt an entire directory tree.

7.18.2 Solution

To produce a single encrypted file containing all files in the directory, with symmetric encryption:

$ tar cf - name_of_directory | gpg -c > files.tar.gpg

or key-based encryption:

$ tar cf - name_of_directory | gpg -e > files.tar.gpg

To encrypt each file separately:

$ find name_of_directory -type f -exec gpg -e '{}' \;

7.18.3 Discussion

Notice the find method uses public-key encryption, not symmetric. If you need a symmetric cipher [Recipe 7.4] or to sign the files [Recipe 7.13], avoid this method, as you'd be prompted for your password/passphrase for each file processed.

7.18.4 See Also

gpg(1), find(1), tar(1).



    Chapter 9. Testing and Monitoring