macOS: create a password protected zip file (archive)

root's picture

So, you are on your mac, you right click on a file and search for "compress with password".
Tough luck, there is no such thing out of the box.

But fear no more! There is a simple way to do this, via terminal! Come on, do not be scared. It is not that difficult.
All you have to do is open terminal and:

1. Go to the directory where you have your folder or file ready to be compressed

fmbp16:~ florian$ cd my_archives 
fmbp16:my_archives florian$

2. Use zip with arguments er where e = encrypt and r = recursive (zip everything).

fmbp16:my_archives florian$ zip -er encrypted_archive.zip my_file_to_be_zipped.txt 
Enter password: 
Verify password: 
  adding: my_file_to_be_zipped.txt (deflated 86%)
fmbp16:my_archives florian$ ls -la 
total 128
drwxr-xr-x    4 florian  staff    128 Nov 17 11:02 .
drwxr-xr-x@ 206 florian  staff   6592 Nov 17 11:02 ..
-rw-r--r--    1 florian  staff   7999 Nov 17 11:02 encrypted_archive.zip
-rw-r--r--    1 florian  staff  56316 Nov 17 11:00 my_file_to_be_zipped.txt
fmbp16:my_archives florian$ rm my_file_to_be_zipped.txt

3. If you remember the password, you can either use the archive utility via graphical interface (a password prompt will appear) or via terminal like this:

fmbp16:my_archives florian$ unzip encrypted_archive.zip 
Archive:  encrypted_archive.zip
[encrypted_archive.zip] my_file_to_be_zipped.txt password: 
password incorrect--reenter: 
   skipping: my_file_to_be_zipped.txt  incorrect password
fmbp16:my_archives florian$ unzip encrypted_archive.zip 
Archive:  encrypted_archive.zip
[encrypted_archive.zip] my_file_to_be_zipped.txt password: 
  inflating: my_file_to_be_zipped.txt  
fmbp16:my_archives florian$ ls -la 
total 128
drwxr-xr-x    4 florian  staff    128 Nov 17 11:03 .
drwxr-xr-x@ 206 florian  staff   6592 Nov 17 11:02 ..
-rw-r--r--    1 florian  staff   7999 Nov 17 11:02 encrypted_archive.zip
-rw-r--r--    1 florian  staff  56316 Nov 17 11:00 my_file_to_be_zipped.txt

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content

root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root