openssl enc -d -aes-256-cbc -in encrypted_archive.tar.gz.enc -out decrypted_archive.tar.gz tar -xzf decrypted_archive.tar.gz Use code with caution. Method 3: Using 7-Zip (For Cross-Platform)
You can provide the password directly in the command, which is as your password will be stored in plain text in your shell's history file.
Run the following command to pipe your compressed tarball directly into OpenSSL for encryption:
tar -czf - /path/to/folder | openssl enc -aes-256-cbc -salt -pbkdf2 -out sensitive_data.tar.gz.enc Use code with caution. password protect tar.gz file
Alternatively, decrypt it back into a standard .tar.gz file first: gpg -d secure_archive.tar.gz.gpg > archive.tar.gz Use code with caution. Method 2: Using OpenSSL
tar -czvf - : Creates the compressed archive and sends it to "stdout" (the pipe).
You can pipe tar directly to openssl without creating an intermediate file: openssl enc -d -aes-256-cbc -in encrypted_archive
But a bundle, no matter how tightly compressed, is not a vault. It is a transparent package. Anyone with a copy of the file can peer inside and extract the contents without asking for permission. In an age where data breaches are daily headlines and privacy is a premium commodity, knowing how to password protect a tar.gz file is not just a technical skill; it is an essential practice in digital hygiene.
7-Zip provides excellent compression ratios and native password encryption capabilities. 7z a -p -mhe=on archive.7z /path/to/directory Use code with caution. -p : Prompts you to input a secure password.
tar czvf - /path/to/folder | openssl enc -aes-256-cbc -out secure_archive.tar.gz.enc Alternatively, decrypt it back into a standard
If you aren't a fan of the command line, there are other ways to protect your treasures:
OpenSSL comes pre-installed on almost all Linux distributions and macOS versions, making it an excellent alternative if GPG is unavailable. Step 1: Compress and encrypt in a single line
Only users with the password can view the contents.