Learn how to password protect a folder in Linux command line. You can use the zip command to create password protected folder in Linux.
This blog outlines step-by-step guide to install zip, compress folders, create password-protected zip files, and unzip archives from the terminal.
How to Zip a Folder in Linux Using the Command Line
Before you begin, make sure the zip command-line tool is installed on your Linux system. If it’s not already installed, open the terminal and run the following command to install both zip and unzip utilities:
sudo apt install zip unzip
Once installed, you can use the zip command to compress folders directly from the Linux terminal.
Zip Command Syntax in Linux
The basic syntax of the zip command is:
zip -r <output_file>.zip <folder_1> <folder_2> ... <folder_n>
-renables recursive compression (required for folders)<output_file>.zipis the name of the zip archive<folder_n>represents one or more folders you want to compress
Example: Zip a Folder in Linux
Suppose you want to zip a folder named Image-Folder into a zip file called Image.zip. Run the following command:
zip -r Image.zip Image-Folder
After the command executes successfully, the Image.zip archive will be created in the current directory.
To verify that the zip file was created, run:
ls -l | grep .zip
Zip a Folder in Linux with a Password
To create a password-protected zip file in Linux, use the -e or --encrypt option. This option encrypts the archive and prompts you to set a password.
For example, to zip Image-Folder into a password-protected archive named Image.zip, run:
zip --encrypt Image.zip Image-Folder
You will be prompted to enter and confirm a password for the zip file.
How to Unzip a Zip File in Linux
To extract a .zip file in Linux, use the unzip command:
unzip Image.zip
Note:
If the zip archive is password-protected, you will be prompted to enter the password during extraction.
