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 files.zip test1 test2 test3 test4 test5
$ zip files.zip test{1,2,3,4,5}

However, the files.zip 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 files.zip by using the -P or –password option of Zip. The below command demonstrates this.

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

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

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 files.zip test1 test2 test3 test4 test5
$ zip --encrypt files.zip 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 files.zip document.

$ unzip files.zip

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 dir.zip test/

It creates a Linux zip with a password called dir.zip. 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 dir.zip test/

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

$ unzip dir.zip

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.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Post

How to Install, Configure and Enable SSH Service in Linux

In Linux, the Secure Shell (SSH) is a method where you can access another computer through a secure and...

The 20 Best MOBAs for Android Device to Try in 2020

In comparison to different Android gaming genres, MOBA is a newcomer. But this short time of presence is enough...

The 20 Best ASCII Games on Linux System in 2020

If you are looking for the ASCII games on Linux, then you are in the right place. Who doesn't...

The 20 Best Offline Games for Android To Enjoy Your Off Times

All of us often face a situation when an internet connection is not available around us. Either we don't...

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 in relation to Linux OS...

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...

15 Best Things To Do After Installing Linux Mint 19 “Tara”

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

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...

You Might Also LikeRELATED
Recommended to you