How To Create A Password Protected Zip Archive

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

where

  • zip is the command
  • archivefilename is the name of the ZIP archive to be created
  • file, file2, ... are list of files to be included in the archive
  • -e is the option that tells ZIP to encrypt the contents using a password typed in the terminal in response to a prompt

Pretty straightforward, huh? Let us create the zip archive and password protect it.

zip newarchive abc.txt xyz.txt -e

The system now prompts you to type the password. Type your secure password.

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?

Taxonomy upgrade extras: 

Comments

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

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.