Sunday, January 24, 2021
Home Linux How to Create Password Protected Zip File or Directories in Linux

How to Create Password Protected Zip File or Directories in Linux

Zip is a widely used utility for packaging and compressing data. It is available on all major operating systems including, Linux and FreeBSD. It is useful for backing up information and saving disk spaces. Moreover, zip files are easier to store and share amongst peers. However, everyday zip files can be opened by anyone who has access to them. So, if you want to protect your information from falling into the wrong hands, you might want to password protected zip file. Today, we will show you how to do this easily using the readily available zip utility for Linux.

Create Password Protected Zip File or Directories

Zip is an all in one solution that provides both packaging and compressing facilities. It is also very easy to add privacy by means of passwords. We will show you how to create Linux zip files with a password using both the terminal and the graphical interface.

Create Zip Files in Linux from the Terminal

Before proceeding, make sure that the zip utility is available on your machine. It is usually pre-installed in most major Linux distributions. You can check for its existence by running the following command.

$ zip --version

If Zip is not available, install it by running one of the following commands in your Linux terminal emulator.

$ sudo apt install zip
$ sudo yum install zip

Now, first, see how to create a simple zip file without any password. The below command will create a zip of five individual files.

$ zip test1 test2 test3 test4 test5
$ zip test{1,2,3,4,5}

However, the document is not very secure since anybody can extract the original files by using the unzip command in Linux. We can add a password for by using the -P or –password option of Zip. The below command demonstrates this.

$ zip -P 12345 test1 test2 test3 test4 test5
$ zip --password 12345 test{1,2,3,4,5}

Both of the above commands are equivalent and creates a password protected zip file called

linux zip command

However, there is one caveat in this operation. Since we are supplying the password as plaintext in the terminal, other users on the system might be able to view this password. Thankfully, you can use the -e or –encrypt option to add a hidden password for your zip.

$ zip -e test1 test2 test3 test4 test5
$ zip --encrypt test1 test2 test3 test4 test5
Enter password: 
Verify password:

When you type any of the above commands and press enter, a prompt will appear, asking for the password. This password is not echoed in your terminal. The command also verifies the password to make sure users have not made spelling mistakes. Now, whenever you want to extract your files, zip will ask for the password. Use the unzip command in Linux to extract the document.

$ unzip

encrypting zip files

Create Zip Files of Directories from the Terminal

Creating zip files of directories is entirely identical to files. Simply pass the name of the directory instead of the file names. Take a quick look at the below command to see how this works.

$ zip -P 12345 test/

It creates a Linux zip with a password called The content of this zip file is a directory named test, which may contain any number of files/directories on its own. Use the following command to password protect zip files of directories securely.

$ zip -e test/

You can unzip easily by using the Linux unzip command, as shown in the below example.

$ unzip

Create Zip Files in Linux from the GUI

Do not worry if you are not very fluent in using Linux terminal commands. You can easily create zip files with passwords directly from the graphical user interface. The below image shows how to create such a file using the GUI on a Ubuntu system.

password protect zip files GUI

Simply select the files you want to compress by left-clicking your mouse and holding, then right-click and select the Compress option from the menu. Simply enter the name for the output zip file in the appropriate placeholder and click on Other Options to expand an additional dialog box. Here you will find the Password field. Finally, enter your password in this box and click on the Create button above.

Select -> Right Click -> Compress -> ADD FILENAME -> Other Options -> ADD PASSWORD -> Create

As you can see, it is a fairly simple process. However, the terminal method is way more productive since it saves a lot of clicks and navigation. You can unzip the file by following the below steps.

Right Click -> Extract Here -> ENTER PASSWORD -> Select OK

The process is entirely the same for compressing directories from GUI. Try that on your own to make sure you’ve learned to password protect zip files or directories correctly.

Ending Thoughts

We have shown how to protect your zip files with passwords using the command line and the GUI. However, we haven’t focused on compression for this guide. Although zip has universal appeal, it does not provide the best compression results. So, if compression is more important to you, then you should use the gzip or bzip2 compressions alongside Linux tar archives.

These are modular utilities that are much more popular among Linux power users due to their reliability and performance. Hopefully, we will write a cover-up on these very soon. Stay with us till then, and don’t forget to leave a comment if you have any questions regarding Linux zip with passwords.



Please enter your comment!
Please enter your name here

Latest Post

How to Install and Configure Gogs Git Service on Ubuntu Linux

The Gogs is a compact and self-hosted hassle-free Git service that you can install on your Ubuntu Linux server...

The 10 Best GNOME Based Linux Distributions To Check Out in 2021

If you have ever used Linux, then there is no chance that you didn’t hear about GNOME. GNOME is...

How to Install and Use GCC Compiler on Linux System

While building the Linux kernel, the developers had to build a free and open-source compiler to create the kernel...

How to Install and Configure Squid Proxy on Linux System

Squid proxy server is an open-source proxy server for Linux distributions. You can install the Squid proxy server on...

Most Talked Post

Most Stable Linux Distros: 5 versions of Linux We Recommend

At the very beginning, I would like to mention why the term ‘Stable’ comes about Linux OS or distro...

Linux or Windows: 25 Things You Must Know While Choosing The Best Platform

Choosing the best platform - Linux or Windows is complicated. Because both the system is versatile and capable of...

Linux Mint vs Ubuntu: 15 Facts To Know Before Choosing The Best One

Ubuntu and Linux Mint are two popular Linux distros available in the Linux community. Ubuntu is a derivative of...

Best Things To Do After Installing Linux Mint 20 “Ulyana”

Linux Mint is one of the best Linux distros for newcomers, especially those who come from other Operating Systems...