Hack 46. Password Protection of Zip files

by Ramesh

Pass the option –P to the zip command to assign a password to the zip file.

  1. # zip -P mysecurepwd var-log-protected.zip /var/log/*

The above option is good if you are using the command inside a shell-script for background jobs. However, when you are performing the compression interactively on the command-line, you don’t want the password to be visible in the history. So, use the option –e as shown below to assign the password.

  1. # zip -e var-log-protected.zip /var/log/*
  2. Enter password:
  3. Verify password:
  4. updating: var/log/acpid (deflated 81%)
  5. updating: var/log/anaconda.log (deflated 79%)

When you are uncompressing a password protected file, it will ask for the password as shown below.

  1. # unzip var-log-protected.zip
  2. Archive: var-log-protected.zip
  3. [var-log-protected.zip] var/log/acpid password: