It all started with a text message from my wife about needing help with a password on a zip file:
wife: I tried to put password in zip file
wife: I followed this page http://smallbusiness.chron.com/create-encrypted-zip-files-mac-44338.html
me: command of: zip -e myzipfile.zip file1.txt file2.txt OR zip -r -e myzipfile ./directory the tricky part is the terminal
wife: I used the terminal but for some reasons, it only creates empty folder
…a bunch of text messages later…me: Here you go – give them this link…
My wife is really smart and quite a decent user of her Mac. She needed to encrypt a zip file because whe was sending some paystubs to some bank loan people.
I know what you are starting to think “but encrypting a zip file is insecure”. And you’re probably right but the fact of the matter is bank employees are severely constrained by their employers and you’re LUCKY if they’re even allowed to open an encrypted zip file. It’s not that they’re incapable of such a feat, but rather that they’re in a financial institution with a whole lot of rules and regulations that make secure electronic delivery of anything quite debatable.
There should be an easy..practically trivial way to compress a directory and put a password on the Mac but the “encrypted with password” part is not easy at all. In this tutorial I’ll walk you through how to do this.
And now for the instructions
These instructions and pictures were done on Yosemite but should apply to future versions of Mac OS X.
Creating a non-encrypted zip file is easy
Lets use an example directory called my directory
Right click on your folder
Choose the ‘Compress’ selection
And now you have a zip file
It’s easy peasy – you now have a *my directory.zip *file. But it isn’t encrypted with a password. Anyone can double click on it and it would show its contents without difficulty.
Creating an encrypted zip file
To create an encrypted zip file you need to use the Mac’s command line. The command line is a vastly different way to interact with the file system. Most of the tutorials that I have seen do not exactly explain how to use the command line. I will make a stab at making this tutorial clearly explain how to use the command line to create the encrypted zip file of a directory.
Before we proceed – you need to agree that you will follow my instructions to the letter….I’m assuming you are nodding your head with a ‘yes’. If you deviate in any way and you get surprising results then go back and try again by following the exact steps.
The usual disclaimer applies – use at your own risk and I’m not responsible if you destroy your Mac 🙂
Create a mydirectory directory in the Documents folder of your mac
Make sure that the mydirectory doesn’t have any spaces in the name.
Note: Your mydirectory folder doesn’t have to be in Documents. It can be anywhere that you can get to with the Finder.
Place your files in the mydirectory directory
Search for terminal in spotlight
Spotlight is the mac’s search facility. If you don’t see it in Finder just press the following keys: COMMAND SPACEBAR
The command is the key with the clover leaf symbol and the spacebar is….the spacebar. When you see the search box type terminal and then double-click on the suggested program like the one shown in the image (below).
Use the Terminal to change directory to mydirectory
In the terminal we’re going to change directory (cd) into the mydirectory folder. Remember that the Terminal is a completely different way of interacting with your file system (the other way is visually through the Finder).
In the terminal you will be typing the cd command followed by a space (i.e. pressing the spacebar).
- In the terminal type: cd
- With your mouse drag the *mydirectory *folder from the finder window into the terminal
In the next step you will press the enter key on your keyboard and within the Terminal you will have changed the directory into mydirectory.
Press the enter key
You should now be in the mydirectory folder. Congratulations…we’re almost there.
Now type cd ..
Type: cd ..
The key thing is typing the letter c and d then a space with the spacebar followed by two periods.
It’s time to zip up the directory with and encrypt it with a password of your choice
Type: zip -re myzipfile.zip ./mydirectory/
There’s a space (i.e. press the spacebar) between the words (see the red lines in picture).
Note that myzipfile.zip is the encrypted zip file that will hold your files. You can use another name for it but make sure that you don’t put spaces in the file name.
Now press the enter key
You’ll be prompted for the encryption password so enter whatever password that you want to use and then press enter. Then type it in again when you see ‘Verify password:’
What you should see
After you re-enter the password in ‘Verify password:’ and then press the enter key you should see the directory being zipped and encrypted.
Time to test the zip file
You’re pretty much done. It’s a good practice to verify that the directory is encrypted in the zip file. So we will use the Terminal that you already have open to open a Finder window to the directory where the zip file is located.
Type: open .
There’s a space between the open and the period.
Open the new zip file in the Finder window
Use the new Finder window to find the zip file that you just created (myzipfile.zip in this case). Double-click on the file.
When you double click the zip file
If you have properly encrypted the zip file then you should get the picture shown below. If you don’t see this then you probably didn’t encrypt the zip file.
Note: the “hello.txt” message just refers to the first file in the directory. When you put in the correct password the zip file will be fully decrypted, so all files will be decrypted.
After you put the correct password
After you put the correct password you should see your directory in the finder windows.
Note: In the image below there is a ‘mydirectory 2’ The reason there’s a ‘2’ next to the directory name because your original directory is in the same location.
Open the directory and verify that the you can open the files without issue
You’re done – CONGRATULATIONS!!!
It’s time to put on your party hat and do the happy dance. You’re done!
Image credit: http://emojipedia.org/party-popper/
Let me know how I can make these instructions better.
If you think I can do a better job with this tutorial – let me know via twitter (@eli4d).
One last thing…
If you think that Apple should improve the encryption zip file – send Tim Cook an email at tcook@apple.com (I’m serious). Looking for an idea of what to send? Here’s a sample:
Email Subject:
Can you (pretty) please improve the Mac OS X Archive utility to allow zip encryption from the Finder
Email Body:
Dear Tim,
*Can you kindly ask your Mac OS X team to add an encryption capability to the Mac’s Archive utility so I can use the the Finder’s built in ‘Compress’ service rather than use tortuous command line tutorials like https://eli4d.com/2015/09/23/how-to-create-an-encrypted-zip-file-on-the-mac
Sincerely,
ENTER_YOUR_FIRST_NAME