The Chalkboard


Create a password protected zip file from the command line

Last Updated: [2023-03-29 Wed 07:06]

Sometimes you need to create a zip file on macOS with a password. This isn’t possible in Finder, and whilst there are 3rd party apps that can do this, macOS does have the ability to create these kinds of files directly from the terminal.

First, open your terminal, and cd to the directory where the files you want to compress are located. Then run one of the following depending on what you require. If you just need to compress a single file, use the first, otherwise, put them in a directory and run the second:

zip -e myarchive.zip myfile.ext
zip -er myarchive.zip mydirectory

You will then be prompted for a password followed by the confirmation of that password. As with most password prompts in the terminal, there is no visual indicator that the password is being typed. Just press enter when done.

You can test the file was created correctly by trying to uncompress the file in Finder. If all is well, you will be prompted to enter the password to decompress the file.


DISCLAIMER: The information provided on this website is generated from my own notes and is provided "as is" and without warranties. Robert Ian Hawdon can not be held responsible for damages caused by following a guide published on this site. This website contains links to other third-party websites. Such links are provided as convienice of the reader. I do not endorce the contents of these third party sites.