HowTo: Create a Password Protected ZIP File in Linux

This is a small note that describes how to encrypt and decrypt a ZIP file from the Linux command line.

I’ll show how to create a password protected ZIP archive from one or several unprotected files or folders.

Warning! The standard ZIP encryption is very weak and could be cracked easily.

Password Protected ZIP File in Linux

Create an encrypted ZIP file secure.zip from some file:

$ zip --encrypt secure.zip file
Enter password: 
Verify password: 
  adding: file (deflated 8%)

Create password protected ZIP archive secure.zip from the several files:

$ zip --encrypt secure.zip file1 file2 file3
Enter password: 
Verify password: 
  adding: file1 (stored 15%)
  adding: file2 (deflated 30%)
  adding: file3 (deflated 45%)

Create an encrypted ZIP archive secure.zip from a folder /var/log/:

$ zip --encrypt -r secure.zip /var/log/
Enter password: 
Verify password: 
  adding: var/log/ (stored 0%)
  adding: var/log/dmesg.0 (deflated 74%)
  adding: var/log/dpkg.log.9.gz (deflated 0%)
  adding: var/log/samba/log.asc-nb (deflated 96%)
***

Use the following command to uncompress a ZIP file:

$ unzip secure.zip
Enter password:
***

Encrypt and Decrypt ZIP Archive in Linux

You were interactively prompted for the password in the examples above.

If you want to create a password protected ZIP file from some shell script, you may want to do it non-interactively.

This method is more insecure, as the password is entered as plain text.

You can easily encrypt and decrypt ZIP files from the Linux command line without being prompted for the password.

Do it as follows:

$ zip -P passw0rd secure.zip file
$ zip -P passw0rd secure.zip file1 file2 file3
$ zip -P passw0rd -r secure.zip /var/log/

Uncompress a password protected ZIP archive:

$ unzip -P passw0rd secure.zip

3 Replies to “HowTo: Create a Password Protected ZIP File in Linux”

  1. Santosh Garole says: Reply

    Hey Guys,

    The above commands are not working for me , I mean even i give the password while doing the zip. but its not asking me the passwd while unzip.

    Thanks
    Santosh G.

  2. For me the archive itself is not encrypted, you can see the list of files. But to extract the files you need a password.

  3. Santosh. probably the reason is the signature file is in the same directory. try to move the zip file to another folder and try to extract. it should ask for a password

Leave a Reply