From what reason do I need to protect the ZIP file with a password ?
The motivation for creating a password protected Zip file comes when you wants to store on disk or to transfer over the internet (email, ftp, ssh, https…etc) a files or an archive with some level of protection beyond the protection that the storage software tool or the communication protocol provides. so creating the a password protected Zip file become a simple and perfect solution for you, means, you add your own password to protect the file or archive so then it can be unlocked only by you or by any other authorizes person that will receive the password from you.
What are the benefits of using a ZIP file ?
The benefits of using the ZIP tool to archive and compress files and folders is mentions at SFCOMPY™ post: Zip or UnZip files and folders
But why we need to use the CLI in order to get password protected Zip file ?
The MacOS Finder GUI doesn’t have a native option to add password protection to the Zip file when you perform archive and compress to your file and folders
What are the best use-cases and scenarios to use a password protected ZIP file ?
- its a simple and perfect use case to attach a password protected archive file to your email a that contains some sensitive information. This is a great solution when you wants that the only dedicate email receiver will have the option to extract the archive file but not any other person that also may share the same computer or email service. One of the simple way to do so, its by email the password protected Zip file and then to text the password to the receiver mobile phone
- When you need to store some sensitive archive files in your USB flash drive while you are carry the flash drive during your traveling and in the scenario that you worry that you may loose or forget the flash drive somewhere. Adding the password to protect the archive Zip file its also a simple and a perfect use-case to protect your data that store in your flash drives
- You want to upload from your computer to your cloud storage or to the web-server some sensitive archive files over the public network, this will gives an extra protection to your secure browser or file transfer protocol and anyone that will be able to capture the archive files will still need a password to extract the data
Any other things I need to know before I create a password protected ZIP file ?
Keep in mind!!! , To avoid the option that you will forever loose access to the protected ZIP file , means, to not be able to read your files\archive data from the protected ZIP file, from the reason that you do not have a long term way to store and to protect the integrity of the passwords or in case that you are not organize enough to remember where the password saved, (means you can’t guaranty that you will find the password when you need it to unlock the ZIP file) then its highly recommended to protect the ZIP file with a password only for immediate and short term needs, and then, after the password protected ZIP file serve it purpose, you have to decide if you wants to erase the ZIP file with the extracted sensitive file and folder from your computer or instead, to keep it and store the unlocked version of the archive ZIP file
How-To and Example:
- To Archive and to Compress files and folders and adding a password protection to the ZIP file, we use the ‘zip’ command with the ‘-er’ switch as the following:
- zip -er Archive_Name.zip File_Or_Folder_TO_Archive
‘r’ : is for recurse into directories, means, it will archives the entire files and folders inside the folder you choose
‘e’ : is to encrypt the archive zip file
- The command will be prompted with a password prompt, then you need to type twice the same password that will protect the ZIP archive file
# For example , given 'myfolder' folder which include two files bash > ls myfolder/ pic1.png report.txt # To archive and compress myfolder with password protect bash> zip -er my_protected_zipfolder.zip myfolder/ Enter password: Verify password: adding: myfolder/ (stored 0%) adding: myfolder/pic1.png (deflated 3%) adding: myfolder/report.txt (deflated 58%) bash> ls -ltr total 512 drwxr-xr-x 4 sfcompy staff 128 Jul 13 16:58 myfolder -rw-r--r-- 1 sfcompy staff 125956 Jul 16 14:16 my_protected_zipfolder.zip # Now, if you try to extract the archive using the Unzip command, you will be prompt to type the password before the ZIP file is extracted bash> unzip my_protected_zipfolder.zip Archive: my_protected_zipfolder.zip creating: myfolder/ [my_protected_zipfolder.zip] myfolder/pic1.png password: inflating: myfolder/pic1.png inflating: myfolder/report.txt
- Same things will happen if you try to extract the ZIP archive file using the Finder GUI, after pressing double click on the ZIP file ‘my_protected-zipfolder.zip’ windows password box will be prompted as you can see at the image below and only after typing the correct password the ZIP archive will be extract