Mac OS X: How to create an encrypted Zip archive of a folder

Posted by Pierre Igot in: Macintosh
March 31st, 2010 • 10:08 am

Mac OS X’s user interface comes with a built-in facility for creating Zip archives, in the form of a command called “Compress…” in the Finder’s “File” menu or in the contextual action menu. (I believe the command used to be called “Archive…” in versions of Mac OS X prior to Mac OS X 10.5, also known as Snow Leopard.)

It works fine for creating simple Zip archives that can then be shared with other Mac or PC users.

But this facility provides no option to create a password-protected or encrypted Zip archive.

I know that you can purchase a third-party tool such as StuffIt Deluxe that provides such an option. But this third-party product is too expensive and feature-rich for my tastes. In addition, the StuffIt product family does not have a very good history under Mac OS X. Its interface is very lousy (especially for decompressing password-protected Zip archives, among other things) and there have been pretty significant bugs in the past.

The truth is that Mac OS X comes with its own feature for creating password-protected or encrypted Zip archives. It’s just that it’s not accessible in the graphical user interface (GUI). You have to use the command line interface.

As per usual in the CLI world, the most simple things are not obvious and if you bring up the man page in Terminal for the zip command, you will spend a fair bit of time figuring out exactly which options you need.

Since I went through this myself two days ago, I thought I would share the result of my investigations. As far as I can tell, in order to create a password-protected and encrypted archive of a folder, you need to type this in Terminal:

zip -ejr [name] [path to folder]

[name] is the name you want to give to the resulting archive file (without the “.zip” extension, which the zip command will add automatically).

And [path to folder] is the complete name of the folder with its full path. Instead of typing it, you can just type zip -ejr [name] followed by a space and then drag-and-drop the target folder onto the command line. Terminal will automatically insert the full path with escape characters if required.

For your information, the “e” option stands for “encryption,” the “j” for “junk the path” (otherwise the zip command will archive the complete folder hierarchy leading to your target folder, which you probably don’t want), and “r” stands for “recursive,” which will force the zip command to include the entire contents of the folder in the archive. (Otherwise it will only archive the folder itself without its contents, which is not exactly useful.)

Once you execute this command, Mac OS X will ask for the desired password (twice, for confirmation), and then create a Zip archive of your folder with your chosen name at the root level of your home folder. (If you want to specify a different location, you need to provide the full path instead of just the name.)

Et voilà.

It’s not fantastically user-friendly, but it’s far cheaper than StuffIt Deluxe, and at least it does not have a lousy GUI.

DISCLAIMER: I am not a CLI expert and there might be a better/more efficient way to do this. But this works for me.


2 Responses to “Mac OS X: How to create an encrypted Zip archive of a folder”

  1. Dega's blog » Blog Archive » Come fare: creare archivi ZIP su Mac says:

    […] Apparentemente esiste anche una funzionalità di OSX che vi permette di creare archivi criptati (protetti da password), ma non è integrata nell’interfaccia utente e deve essere quindi richiamata da riga di comando tramite il Terminale: […]

  2. On Encryption | John Hendron at VCU says:

    […] Check out this website for instructions on how to create encrypted ZIP files on the Mac. I’m interested in seeing if these files are usable on the PC side. […]