When working with files, protecting sensitive data is a key concern. Especially when sharing files via email or online platforms, setting a password on a ZIP file is an effective way to secure your data. If you’re using a Linux operating system, this task can be easily done using built-in tools. This article will guide you through the process in detail and help troubleshoot common issues.
1️⃣ Setting a Password for a ZIP File on Linux via Command Line
Before getting started, make sure the necessary tools are installed. Open a terminal and run the following command:
sudo apt install zip unzip
To compress a file and simultaneously set a password, navigate to your target directory and use the following command:
zip -re filename.zip file
For example, to password-protect a file named sensitive-data.txt
in your Downloads folder:
cd ~/Downloads
zip -re secure-archive.zip sensitive-data.txt
The -r
flag enables recursive compression (useful for directories), while -e
prompts for a password. To compress an entire folder with password protection:
zip -re filename.zip *
2️⃣ Using Archive Manager to Set a Password
Open the Applications Menu and search for “Archive Manager.”
- Launch the application and drag-drop your file into the interface.
- File name: Set a name for your ZIP archive.
- Other options: Choose to set a password for the file.
- Save: Save the ZIP file with your chosen settings.

This method is compatible with Ubuntu 22.04 and newer versions. For Ubuntu 20.04 and older, right-click on the file, choose “Compress,” and follow a similar process to set a password.
Make sure you’ve installed the necessary tools:
sudo apt install rar unrar
sudo apt install zip unzip
🔧 Common Errors & How to Fix Them
Error | Explanation | Solution |
---|---|---|
Cannot open ZIP file | Might be due to a wrong password or a corrupted file | Double-check the password. If forgotten, recovery is not possible. Try using ZIP repair tools if the file is corrupted. |
Unable to compress file with password | Missing the -e flag or incorrect syntax | Verify the command syntax: zip -e . If needed, use -P to pass the password directly in the command (note: less secure). |
ZIP file corrupted after password protection | Could be due to incompatibility between ZIP versions | Update your ZIP tool to the latest version, or use an alternative like 7zip for encryption. |
Weak or guessable password | Password isn’t strong enough, making it easy to crack | Use a strong password with a mix of special characters, uppercase, lowercase, and numbers. |
🔏 Security Considerations
While password-protecting your files adds an extra layer of security, note that ZIP file encryption is not the strongest form of protection. For highly sensitive data, consider using more robust encryption tools like GPG (GNU Privacy Guard).
By following these methods, you can effectively protect your ZIP and RAR files on Ubuntu and Linux, safeguarding your valuable information.