{"id":591,"date":"2021-07-16T14:39:27","date_gmt":"2021-07-16T21:39:27","guid":{"rendered":"https:\/\/sfcompy.com\/blog\/?p=591"},"modified":"2021-08-14T14:51:16","modified_gmt":"2021-08-14T21:51:16","slug":"password-protected-zip-file-macos-cli","status":"publish","type":"post","link":"https:\/\/sfcompy.com\/blog\/password-protected-zip-file-macos-cli\/","title":{"rendered":"Password Protected Zip file &#8211; MacOS CLI"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\"><p>From what reason do I need to protect  the ZIP file with a password ? <\/p><\/blockquote>\n\n\n\n<p>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&#8230;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. <\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>What are the benefits of using a ZIP file ?<\/p><\/blockquote>\n\n\n\n<p>The benefits of using the ZIP tool to archive and compress files and folders is mentions at SFCOMPY\u2122 post: <a href=\"https:\/\/sfcompy.com\/blog\/zip-unzip-file-and-folders-macos-cli\/\" data-type=\"URL\" data-id=\"https:\/\/sfcompy.com\/blog\/zip-unzip-file-and-folders-macos-cli\/\">Zip or UnZip files and folders<\/a>&nbsp;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>But why we need to use the CLI in order to get password protected Zip file ?<\/p><\/blockquote>\n\n\n\n<p>The MacOS Finder GUI doesn&#8217;t have a native option to add password protection to the Zip file when you perform archive and compress to your file and folders <\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>What are the best  use-cases and scenarios to use a password protected ZIP file ?<\/p><\/blockquote>\n\n\n\n<ul><li>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 <\/li><\/ul>\n\n\n\n<ul><li>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<\/li><\/ul>\n\n\n\n<ul><li>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 <\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>Any other things I need to know before I create a password protected ZIP file ?<\/p><\/blockquote>\n\n\n\n<p>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&#8217;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 <\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>How-To and Example:<\/p><\/blockquote>\n\n\n\n<ul><li> To Archive and to Compress files and folders and adding a password protection to the ZIP file, we use the &#8216;zip&#8217; command with the &#8216;-er&#8217; switch as the following:<\/li><li>zip -er  Archive_Name.zip    File_Or_Folder_TO_Archive<\/li><li>when:<br>&#8216;r&#8217; : is for recurse into directories, means, it will archives the entire files and folders inside the folder you choose <br>&#8216;e&#8217; : is to encrypt the archive zip file<\/li><li>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<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted style=&quot;color:gold;&quot;\"># For example , given 'myfolder' folder which include two files  \n\nbash &gt; ls myfolder\/\n pic1.png    report.txt\n\n# To archive and compress myfolder with password protect\n\nbash&gt; zip -er my_protected_zipfolder.zip myfolder\/\n Enter password: \n Verify password: \n   adding: myfolder\/ (stored 0%)\n   adding: myfolder\/pic1.png (deflated 3%)\n   adding: myfolder\/report.txt (deflated 58%)\n\nbash&gt; ls -ltr\n total 512\ndrwxr-xr-x  4 sfcompy  staff     128 Jul 13 16:58 myfolder\n-rw-r--r--  1 sfcompy  staff  125956 Jul 16 14:16 my_protected_zipfolder.zip\n\n# 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\n\nbash&gt; unzip my_protected_zipfolder.zip \n Archive:  my_protected_zipfolder.zip\n    creating: myfolder\/\n [my_protected_zipfolder.zip] myfolder\/pic1.png password: \n   inflating: myfolder\/pic1.png       \n   inflating: myfolder\/report.txt<\/pre>\n\n\n\n<ul><li>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 &#8216;my_protected-zipfolder.zip&#8217; 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<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"736\" height=\"309\" src=\"https:\/\/sfcompy.com\/blog\/wp-content\/uploads\/2021\/07\/sfcompy_posword-protected-zip-file-prompt.png\" alt=\"\" class=\"wp-image-603\" srcset=\"https:\/\/sfcompy.com\/blog\/wp-content\/uploads\/2021\/07\/sfcompy_posword-protected-zip-file-prompt.png 736w, https:\/\/sfcompy.com\/blog\/wp-content\/uploads\/2021\/07\/sfcompy_posword-protected-zip-file-prompt-600x252.png 600w, https:\/\/sfcompy.com\/blog\/wp-content\/uploads\/2021\/07\/sfcompy_posword-protected-zip-file-prompt-300x126.png 300w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><\/figure><\/div>\n\n\n\n<ul><li>DONE!<\/li><\/ul>\n\n\n\n<p> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;etc) a files or an archive with some level of protection beyond the protection&#8230;<\/p>\n<p class=\"more-link-wrap\"><a href=\"https:\/\/sfcompy.com\/blog\/password-protected-zip-file-macos-cli\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &ldquo;Password Protected Zip file &#8211; MacOS CLI&rdquo;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":592,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50,62,61,63],"tags":[73,79,81,82,80],"_links":{"self":[{"href":"https:\/\/sfcompy.com\/blog\/wp-json\/wp\/v2\/posts\/591"}],"collection":[{"href":"https:\/\/sfcompy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sfcompy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sfcompy.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sfcompy.com\/blog\/wp-json\/wp\/v2\/comments?post=591"}],"version-history":[{"count":0,"href":"https:\/\/sfcompy.com\/blog\/wp-json\/wp\/v2\/posts\/591\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sfcompy.com\/blog\/wp-json\/wp\/v2\/media\/592"}],"wp:attachment":[{"href":"https:\/\/sfcompy.com\/blog\/wp-json\/wp\/v2\/media?parent=591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sfcompy.com\/blog\/wp-json\/wp\/v2\/categories?post=591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sfcompy.com\/blog\/wp-json\/wp\/v2\/tags?post=591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}