How do I create an encrypted (password protected) zip file?
9 Answers
This will prompt for a password:
zip --encrypt file.zip files
This is more insecure, as the password is entered/shown as plain text:
zip --password (password) file.zip files
Warning, the standard zip encryption is very weak and is easily cracked.
Note, Use -r to zip directory and subdirectory recursively.
- 646
- 3,230
Comments and answers have mentioned the default zip encryption is weak, but since there is no code example, here is on with .7zip:
sudo apt-get install p7zip-full # install 7zip
7za a -tzip -p -mem=AES256 foo_file.zip foo_folder # encrypt folder
Commands explained:
7za: Use 7zipa: Append? / Adding files? (efor extraction)-tzip: Use .zip format instead of default .7z-p: specify a password for encryption-mem=AES256: Use AES256 encryptionfoo_file.zip: Name of .zip filefoo_folder: Name of folder to encrypt
Answer based on: https://www.tecmint.com/7zip-command-examples-in-linux/
- 223
- 471
You can also right-click on a folder or file(s) in Nautilus and select "Compress...". In the resulting window, you can expand the "Other Options" section to enter a password.

If the password field or any of the other options are not enabled, then the selected compression option does not support it. Select a different one from the list after the filename. According to the documentation:
Currently, only 7-Zip, ZIP, RAR and ARJ archives support encryption
- 1,647
Encrypt
gpg -c your.zip
creates your.zip.gpg
Decrypt:
gpg your.zip.gpg
More details including directories.
- 183
The metadata (filenames) of an encrypted zip can be read with unzip -l
The solution, as described in that link is to double-zip it but it is really not elegant.
Also, some email providers block that kind of attachment, gmail for example.
- 63
Here's a simple way of compressing by encrypting and extracting by decrypting.
You can use the following to compress zip -er output.zip <folder_to_compress>.
It will prompt you for a password. Enter password.
To decrypt/extract use unzip <output.zip>.
- 121
with bsdtar
Encrypt a_file, creating the encrypted archive encrypted.zip (you'll be prompted for a password):
bsdtar --options zip:encryption -acf encrypted.zip a_file
Decrypt and extract the file from the encrypted archive:
bsdtar -xf encrypted.zip
The -a option when creating the archive makes bsdtar choose the archive format and its compression using the ending of the archive, .zip. If you don't add -a, you'll get this error message:
bsdtar: Unknown module name: `zip'
- 1,165