How to password protect a zip file on Linux with the zip command

You will turn a file or folder into a ZIP archive that asks for a password before it opens, using the zip command in a Linux terminal. It suits any Linux user who wants to move sensitive files without leaving them readable. You only need a terminal and the zip package.

How to secure our zip file with password on Linux, by GoliTech on YouTube. 1 min 43 s.

Video length
1 min 43 s
Time to do it
5 minutes
Difficulty
Easy
Steps
7

What you need

Steps

  1. Open a terminal and use cd to move into the folder that holds the files you want to protect, for example cd ~/Documents/reports.

  2. Check the tool is there by running zip --version. On Ubuntu or Debian install it with sudo apt install zip, on Fedora with sudo dnf install zip.

  3. Create the archive with the -e flag, listing the files to add: zip -e secret.zip notes.txt budget.txt. The -e flag is what makes zip ask for a password.

  4. Type your password at the Enter password prompt and press Enter, then type it again at Verify password. Nothing shows on screen while you type.

  5. To protect a whole folder, add the -r flag so zip walks into it: zip -e -r project.zip project/.

  6. List the contents with unzip -l secret.zip, then test the password by extracting to a scratch folder such as unzip secret.zip -d /tmp/test.

  7. Once the archive opens with your password, delete the original unencrypted files with rm, or move them somewhere safe.

Tips and common mistakes

Do not use -P yourpassword on the command line, because the password stays in your shell history; use -e so zip prompts you instead.

Standard zip encryption is weak, so for really sensitive data use 7z a -p -mhe=secret archive.7z files for AES-256.

Pick a long passphrase you can retype, since a lost ZIP password is very hard to recover.

Standard password-protected ZIPs open in Windows Explorer and macOS Archive Utility, but AES archives need 7-Zip or a similar tool.

Questions

How do I password protect a folder instead of single files?

Add the -r flag so zip includes everything inside the folder, for example zip -e -r project.zip project/. Without -r only an empty folder entry is stored.

How do I remove the password later?

Unzip the archive with your password, then create a new archive without the -e flag. You cannot strip encryption from an existing ZIP in place.

Will the person receiving the file need Linux?

No. A standard password-protected ZIP opens on Windows and macOS too, as long as they have the password.

This guide was drafted from the video's details and general task knowledge. It has not been checked against the full video. Check the video and relevant product instructions before following a procedure. Report a correction.

More in Apps & Software

See all