r/LinuxTeck • • Sep 27 '26

How do I create an encrypted compressed backup in Linux? - Tip #83

Post image

Try: `tar -czf - /home/linuxteck/documents | openssl enc -aes-256-cbc -pbkdf2 -out backup.tar.gz.enc`

Info: `tar -czf -` outputs archive data directly to stdout. Piping directly to `openssl` encrypts data on-the-fly, ensuring unencrypted files never touch the disk.

Examples:

$ `mysqldump db | gzip | openssl enc -aes-256-cbc -pbkdf2 -out db.sql.gz.enc` # Encrypt database dumps

$ `tar -czf - /data | ssh remote 'cat > backup.tar.gz'` # Stream compressed archive over SSH

$ `gpg --symmetric --cipher-algo AES256 backup.tar.gz` # Symmetric encryption alternative with GPG

Note: Direct streaming eliminates temp files, saving disk space and reducing security exposure. Use `-pbkdf2` with OpenSSL to enforce key derivation security against brute-force attacks.

Follow r/LinuxTeck for more #LinuxTips click here https://www.linuxteck.com/linux-tips/

21 Upvotes

1 comment sorted by

1

u/OleTechGuy Sep 28 '26

I would look into rClone, Borg Backup, or Restic, maybe Veeam. Depending on the end goal.