SOURCE_DIR=$1 OUTPUT_BASE=$2

zip -r -e --password=yourpassword -AES256 secured_backup.zip my_folder/ (Note: Not all zip versions on Linux support AES-256; check your man page.) If you already have a .tar.gz file, simply wrap it inside an encrypted zip container:

Make it executable: chmod +x secure-tar.sh A standard tar.gz file is a convenience, not a vault. Leaving sensitive data in an unencrypted archive is equivalent to storing your secrets in a cardboard box.

GPG is another industry-standard tool. Unlike OpenSSL (which uses a single password/key), GPG can use either a passphrase (symmetric encryption) or public/private key pairs. For pure password protection, we'll use symmetric encryption. gpg --symmetric --cipher-algo AES256 backup.tar.gz This produces a file named backup.tar.gz.gpg . GPG will ask you to enter and confirm a passphrase.

By adding a password through or GPG , you transform that cardboard box into a steel safe. The process takes only a single extra command, but the security gains are immeasurable.

In the world of Linux and Unix-based systems, the tar command is the gold standard for archiving files. When you combine it with gzip (creating a .tar.gz or .tgz file), you get a highly efficient, compressed archive perfect for backups, software distribution, and data transfer.

To add a password, you need to layer encryption on top of or within the archival process. Below are the four best methods, ranked by security and practicality. Best for: Maximum security, cross-platform compatibility, and single-file encryption.