ZIP is a very popular compression and file packaging utility for Unix-like operating systems as well as Windows. While perusing through the zip man page, I discovered some useful options for protecting zip archives.
Read Also: How to Password Protect a Vim File in Linux
In this post, I will show you how to create a password protected zip file on the terminal in Linux. This will help you learn a practical way of encrypting and decrypting contents of zip archive files.
First install zip utility in your Linux distribution using the package manger as shown.
$ sudo yum install zip [On CentOS/RHEL] $ sudo dnf install zip [On Fedora 22+] $ sudo apt install zip [On Debian/Ubuntu]
How to Create Password Protected ZIP in Linux
Once installed, you can use the zip command with -p
flag to create a password protected zip archive called ccat-command.zip from the directory of files called ccat-1.1.0 as follows.
$ zip -p pass123 ccat-command.zip ccat-1.1.0/
However, the above method is absolutely insecure, because here the password is provided as clear-text on the command line. Secondly, it will also be stored in the history file (e.g ~.bash_history for bash), meaning another user with access to your account (more especially root user) will easily see the password.
Therefore, try to always use the -e
flag, it shows a prompt allowing you to enter a hidden password as shown.
$ zip -e ccat-command.zip ccat-1.1.0/
How to Unzip Password Protected ZIP in Linux
To unzip and decrypt the content of the archive file called ccat-command.zip, use the unzip program and provide the password you entered above.
$ unzip ccat-command.zip
That’s It! In this post, I described how to create a password protected zip file on the terminal in Linux. If you have any queries, or other useful related tip/tricks to share, use the comment form below ping us.
The example:
Does not work on a folder, as it only compresses the folder and not its content. Indeed, in the output of the example we can get a hint of this fact based on the “(stored 0%)”, which means that the archive is compressed down to 0%, i.e., no actual content.
To compress a folder and its content, encrypted, we need to add -r:
will work. We will notice it because we get a comprehensive output and a statement of how much deflation applied to each and every file.
This worked by me in Ubuntu:
zip --encrypt 2022-12-02_backup.zip -r folder_to_backup
.Be good!
@Jirka,
Thanks for sharing the tip, hope it will help other Linux users…
It is not worked! work this:
zip -P asdasdas archive.zip asdasdas
.