Link to home
Start Free TrialLog in
Avatar of Sida Say
Sida SayFlag for Cambodia

asked on

How to encrypt file with tar command or other compress option on Linux?

Dear All,

I want to encrypt my database and and application back up file with compression like tar command.
Do you have any idea how to do this?
ASKER CERTIFIED SOLUTION
Avatar of Shiju Jacob
Shiju Jacob
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use zip with -e option for password protection.

http://linux.die.net/man/1/zip
You can do without saving temp unencrypted files:

tar cf - /data/* | pbzip2 -9 | openssl ....
(choose openssl parameters from ohers' posts)
Restore:
openssl -d ... | bzcat | tar tvf -
don't use the built in zip - the encryption is of low quality and easily bypassed.

openssl or gpg are good choices, but don't compress and should be used to encrypt a tgz after the fact. Versions are of course available to decrypt on windows.

7z is available for linux, can compress well, and encrypt with AES@256 bit.  In ubuntu (at least) you can install by typing "apt-get install p7zip-full"

command then is "7z a -p<password> <archive>.7z <filespec>"
I prefer tar and gpg.

This command will tar up the files, and compress with gzip, then encrypt with gpg.

tar czvpf - file1.sql file2.txt  | gpg --symmetric --cipher-algo aes256 -o myarchive.tar.gz.gpg

it will ask you from a passphrase that you will need to decrypt later.

To decrypt and extract you would run:

gpg -d myarchive.tar.gz.gpg | tar xzvf -