In my previous post we discussed how to create and extract ZIP archives. This post will teach you how to password protect your ZIP archives. While creating a ZIP archive, optionally, you can encrypt its contents using a password. Take advantage of this option to secure your ZIP archives. This tutorial is short and easy to learn.
How to password protect ZIP archives?
Let us assume we have two text files - abc.txt and xyz.txt in the present working directory.
[sudheer@localhost zip]$ ls abc.txt xyz.txt
Let us now create newarchive.zip and encrypt its contents with a password. The syntax is:
zip archivefilename file1, file2, ... -e
Pretty straightforward, huh? Let us create the zip archive and password protect it.
zip newarchive abc.txt xyz.txt -e
zip newarchive abc.txt xyz.txt -e Enter password:
ZIP will make sure that you are not making a typographical mistake while entering the password. Verify your password by typing it again.
zip newarchive abc.txt xyz.txt -e Enter password: Verify password:
If both the passwords match, the ZIP archive will be created with its contents encrypted with your password.
zip newarchive abc.txt xyz.txt -e Enter password: Verify password: adding: abc.txt (stored 0%) adding: xyz.txt (stored 0%)
Find the newarchive.zip in your present working directory. When you extract this ZIP archive you will be prompted to type your password. Do you recall what command to use to extract the ZIP archive?
unzip newarchive.zip Archive: newarchive.zip [newarchive.zip] abc.txt password:
If the password you type while extracting is correct, unzip extracts the contents.
unzip newarchive.zip Archive: newarchive.zip [newarchive.zip] abc.txt password: extracting: abc.txt extracting: xyz.txt
If the password entered does not match the encrypted password, unzip will display the warning and exit without extracting the contents of the ZIP archive.
Example of a failed extract attempt:
unzip newarchive.zip Archive: newarchive.zip [newarchive.zip] abc.txt password: skipping: abc.txt incorrect password skipping: xyz.txt incorrect password
Now you know how to password protect your ZIP archives, don't you?
create a password protected zip by a a script
Dear Sudheer
when we use -e, system will prompt for the password!!
but how can we create a password protected zip by a a script/command line?
by supplying password in the script.?? so that we can use this in cronjob also.
thanks in advance.
-Numan
Post new comment