How To Create & Compress a ZIP File with Password on Linux

Learn how to install and compress files or folders with ZIP adding a password for Linux systems.

Step 1: Install ZIP in Linux

The first step is to install the application in our system, and for this, we have the following options

sudo yum install zip (CentOS/RHEL)
sudo dnf install zip (Fedora)
sudo apt install zip (Debian/Ubuntu)

There you have all the Zip installation commands according to the version of the Linux distribution.

Step 2: Create a Password Protected ZIP File

To establish a password protected file it will be necessary to use the -P indicator.

For example, to create a password protected compressed file called Solvetic.zip from the “Documents” file directory we will execute the following:

zip -p pass123 TheLinuxCode.zip /home/augusto/Documents/

The result will be the following:

There we must take into account the following:

  • -p: Assigns a password to the selected file.
  • Pass123. Password assigned.
  • Solvetic.zip: File to protect.
  • /home/augusto/Documents Directory where the file is located.

Although this is the practical method, it has a security failure when entering the password directly on the terminal line.

To improve security, it is ideal to use the -e flag, which displays a warning that allows us to enter a hidden password and confirm it like this:

Finally remember that to decompress a file we must use the following syntax:

unzip file.zip

Thus, we have seen how the zip utility helps us to add extra layers of security to the files that are necessary.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *