Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Password Protect Zip Files on Mac Using Terminal

· 4 min read · Home Tech

In this article
  1. Why Use Terminal Instead of Finder?
  2. The Basic Command
  3. Encrypting a Folder
  4. Choosing a Strong Password
  5. Common Problems and Solutions
  6. Verifying the Encryption
  7. Alternatives to Terminal
  8. Frequently Asked Questions

Yes, you can password-protect a zip file on a Mac using the built-in Terminal app with the zip command and the -e flag. This article explains the exact command, how it works, and common issues you might encounter.

Why Use Terminal Instead of Finder?

Finder on macOS does not offer a built-in option to create an encrypted, password-protected zip archive. You can compress files, but the resulting zip is not encrypted. Terminal provides a native, free solution using the zip command, which has been part of macOS for years. This method is ideal for users who prefer command-line tools or need to automate the process in scripts.

The Basic Command

Open Terminal (found in Applications/Utilities) and use the following syntax:

zip -e archive.zip file1.txt file2.jpg

Replace archive.zip with the desired name of your output file, and list the files you want to include. The -e flag prompts you to enter and verify a password. Once entered, the zip file is created with AES-256 encryption (on modern macOS versions).

Encrypting a Folder

To compress and encrypt an entire folder, use the -r (recursive) flag:

zip -er archive.zip MyFolder

This will include all files and subfolders within MyFolder. The -r flag is essential for directories; without it, the folder itself is added but its contents are not.

Choosing a Strong Password

The security of your encrypted zip depends entirely on the password you choose. A weak password can be cracked with brute-force tools. Use a password that is:

  • At least 12 characters long
  • A mix of uppercase and lowercase letters, numbers, and symbols
  • Not a common word or phrase
  • Unique to this archive (don't reuse passwords)

Consider using a password manager to generate and store a strong random password.

Common Problems and Solutions

Several issues can arise when using the zip command:

  • Command not found: If you see “zip: command not found”, ensure you are in the correct shell and that the path includes /usr/bin. Usually, this is not an issue on standard macOS.
  • Password prompt not appearing: If you use -e and the prompt doesn't show, check that you're not piping input. The command must be run interactively.
  • File names with spaces: Quote file names or use tab completion. For example: zip -e archive.zip "My File.txt".
  • Archive created but not encrypted: Verify that you used the -e flag. Without it, the zip is just compressed, not protected.

Verifying the Encryption

After creating the archive, you can verify that it is encrypted by listing its contents with the unzip command:

unzip -l archive.zip

If the archive is encrypted, you will be prompted for a password. Additionally, you can use the zipinfo command to see the encryption method:

zipinfo -v archive.zip

Look for “AES-256” in the output to confirm strong encryption.

Alternatives to Terminal

If you prefer a graphical interface, several third-party apps offer encrypted zip creation. However, they are not built into macOS. Another built-in option is to use Disk Utility to create an encrypted disk image (.dmg), which also provides password protection. The zip method is often simpler for quick file transfers.

Frequently Asked Questions

How do I unzip a password-protected file?

Double-click the zip file in Finder, and macOS will prompt for the password. Alternatively, use unzip archive.zip in Terminal and enter the password when prompted.

Can I change the password of an existing zip?

No, the zip command does not support changing the password of an existing archive. You must create a new zip with the new password and delete the old one.

Is the encryption secure?

Modern macOS uses AES-256 encryption, which is considered secure. However, the strength depends on your password. Avoid using the default ZipCrypto (legacy) encryption, which is weaker; the -e flag on current macOS versions defaults to AES.

Why does my zip file open without a password on Windows?

Some older Windows tools do not support AES-encrypted zips. Use a modern tool like 7-Zip or the built-in Windows 11 extraction, which supports AES. If the archive was created with ZipCrypto, it will open on most systems but is less secure.

Can I encrypt a zip file without being prompted for a password?

Yes, you can provide the password in a script, but it will be visible in the command line history. For example: zip -e -P 'YourPassword' archive.zip file.txt. This is not recommended for security reasons.