- HowTo: Create a Password Protected ZIP File in Linux
- Password Protected ZIP File in Linux
- Encrypt and Decrypt ZIP Archive in Linux
- How to Create a Password Protected ZIP File in Linux
- How to Create Password Protected ZIP in Linux
- How to Unzip Password Protected ZIP in Linux
- How to Create a Zip with Password in Linux
- Create a Zip file with Password in Linux (Using Terminal)
- Create a Password-protected zip in Linux (Using GUI)
- Can I Password Protect an existing Zip file
HowTo: Create a Password Protected ZIP File in Linux
This is a small note that describes how to encrypt and decrypt a ZIP file from the Linux command line.
I’ll show how to create a password protected ZIP archive from one or several unprotected files or folders.
Warning! The standard ZIP encryption is very weak and could be cracked easily.
Password Protected ZIP File in Linux
Create an encrypted ZIP file secure.zip from some file:
$ zip --encrypt secure.zip file Enter password: Verify password: adding: file (deflated 8%)
Create password protected ZIP archive secure.zip from the several files:
$ zip --encrypt secure.zip file1 file2 file3 Enter password: Verify password: adding: file1 (stored 15%) adding: file2 (deflated 30%) adding: file3 (deflated 45%)
Create an encrypted ZIP archive secure.zip from a folder /var/log/ :
$ zip --encrypt -r secure.zip /var/log/ Enter password: Verify password: adding: var/log/ (stored 0%) adding: var/log/dmesg.0 (deflated 74%) adding: var/log/dpkg.log.9.gz (deflated 0%) adding: var/log/samba/log.asc-nb (deflated 96%) ***
Use the following command to uncompress a ZIP file:
$ unzip secure.zip Enter password: ***
Encrypt and Decrypt ZIP Archive in Linux
You were interactively prompted for the password in the examples above.
If you want to create a password protected ZIP file from some shell script, you may want to do it non-interactively.
This method is more insecure, as the password is entered as plain text.
You can easily encrypt and decrypt ZIP files from the Linux command line without being prompted for the password.
$ zip -P passw0rd secure.zip file $ zip -P passw0rd secure.zip file1 file2 file3 $ zip -P passw0rd -r secure.zip /var/log/
Uncompress a password protected ZIP archive:
$ unzip -P passw0rd secure.zip
How to Create a Password Protected ZIP File in Linux
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.
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.
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.
How to Create a Zip with Password in Linux
A zip archive is a file format which is used to store compressed data. A zip file can store files and folders in multiple level of compressions, making it easier to archive, transport & manage a large number of files/folders.
In Linux zip files can be accessed or created using packages called zip & unzip. Both of these packages will either come pre-installed with your Linux system or you will need to fetch them from the repositories.
Here in this short tutorial I am going to show you how you can create a zip archive in Linux with password protection.
There are two ways to do it. You can either use the command line interface in Linux (often called terminal or console) OR if you are using a Desktop Environment such as Gnome, KDE, Xfce, etc, you can use GUI applications such as Ark, File Roller, and Engrampa.
Create a Zip file with Password in Linux (Using Terminal)
1. First step is to make sure that you have the correct utilities installed. If you are not already in the command-line interface (CLI), open the terminal and navigate to the location where the file that you need to add to zip archive are. You can do this easily with the cd command.
(Note: sudo is only needed if you are installing from a non-root account.)
2. Now type the following command (for Debian and Ubuntu based systems) :
sudo apt install zip unzip
For CentOS you will need to type:
sudo yum install zip unzip
And for Arch-based system, type:
3. With this done, verify that you are in the correct location and type ls in the terminal to verify that all of your files are there too.
4. Now type this is terminal.
zip -P password_here -r output_file_name.zip file1_to_add_to_archive file_2 folder_1
5. Hit enter.
The command may look confusing at first but let me explain with an example.
If I want to create a zip archive with ‘file1, file2, folder8, folder and file with space‘ in it with the password [email protected] and a file name archive.zip the command would look like this:
zip -P [email protected] -r archive.zip file1 file2 folder8 'folder and file with space'
After the command finishes executing, you can run the ls command to verify that your archive is there. To unzip the file, simply type this on your terminal:
It should now ask for the password & once you do the same, the content of the zip archive should be extracted.
Create a Password-protected zip in Linux (Using GUI)
There are many GUI programs that you can use to create zip files with passwords. But for this tutorial, I am going to use Ark. This main reason for this is the fact that Ark is Available in main repo’s of CentOS, Ubuntu, Debian, & as well as Arch Linux; Also it is very easy to use.
1. First install Ark from the app store that your Linux distribution provides. You can also use the terminal to do so, here are the commands:
For Ubuntu/Debian based Systems:
For Arch based Systems the command is:
2. After the installation is successful, open a file manager and navigate to folder where the data that you want to zip is.
3. Select the files and folders that you want to archive as a password-protected zip, right-click, click on “Compress” and select “Compress to”.
4. Enter the file name, and set the type to application/zip. After that, click on Password Protection menu and set a password for your zip file.
5. Click ok, let it process and you should now have a password-protected zip file with your stuff in it.
6. If for some reason you don’t get the right-click menu entry for Compress, here is an alternate way to do it.
7. Open Ark either from your app drawer or terminal, click on Archive on the top menu and select New.
8. Again, enter a file name, set type as application/zip and set a password using the Password Protection menu.
9. Now simply drag and drop your files into the Ark window to add them to your zip archive.
Can I Password Protect an existing Zip file
No it is not possible to add a password to an existing zip file. But what you can do instead is unzip the contents of the zip file and create a new archive with the methods above.
If you are looking for other ways to secure your data, checkout this post on how to encrypt a drive (or partition) in Linux. An encrypted drive is better than a zip because you can add more file to it later on and also access and change the content without any hassle.