Question: How do I create an encrypted compressed backup in Linux?
Try: tar -czf - /home/linuxteck/documents | openssl enc -aes-256-cbc -pbkdf2 -out backup.tar.gz.enc
Info: tar -czf - writes the compressed archive directly to standard output. Piping it to openssl enc encrypts the archive on the fly, so the unencrypted backup does not need to be stored as a temporary file on 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 temporary archive files, saving disk space and reducing exposure of unencrypted backup data. Use -pbkdf2 with OpenSSL for password-based key derivation. Keep the encryption password securely stored because it is required to restore the backup.
Leave a Reply