LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Encryption using tar bzip gzip and zip (https://www.linuxquestions.org/questions/linux-newbie-8/encryption-using-tar-bzip-gzip-and-zip-4175437650/)

rakrr786 11-18-2012 02:36 AM

Encryption using tar bzip gzip and zip
 
Hi
can any one tell me if i can encrypt a file using tar or tar bzip/gzip or zip command while taking a backup just as i can do with vi

Elv13 11-18-2012 02:46 AM

you can tar something, encrypt it then compress it using bzip/gzip, or tar something, compress it and encrypt it. According to the tar manpage, it is not supported directly, but based on the way tar and gz/bz2 work, it is simply an other layer in between. You are free to use one of many crypt tools available.

catkin 11-18-2012 03:24 AM

Encrypted data should not have any discernible patterns so should not compress well. If that theory is correct, compression followed by encryption should produce a smaller file than encryption followed by compression.

malekmustaq 11-18-2012 04:23 AM

Quote:

Originally Posted by rakrr786 (Post 4831831)
Hi
can any one tell me if i can encrypt a file using tar or tar bzip/gzip or zip command while taking a backup just as i can do with vi


You may want to do this---

Code:

tar czf foo.tar.gz  foo.txt && gpg -c foo.tar.gz
Enter password when prompted.

You may remove the original file or delete them after gpg encrypted file is made. Or include deletion within command:

Code:

tar czf foo.tar.gz foo.txt && gpg -c foo.tar.gz && rm -f foo.txt
this one creates an encrypted archive and removes the unencrypted original.

From thence you may create a script to be envoked when encrypting file.

Hope that helps. Good luck.

jefro 11-18-2012 12:26 PM

tar cf - /path/to/data | 7z a -si archivename.tar.7z


http://www.commandlinefu.com/command...7z-compression

The post also has some additions useful.


"What others think

some newer versions of tar support the '--lzma' option

LZMA is the same type of compression used by 7zip

This is a cleaner option, though I suppose it is only supported by newer versions of tar which could be a problem...
tar c --lzma /path/to/data > archivename.tar.lzma
Comment by infinull 174 weeks and 4 days ago

According to google, GNU tar supports the lzma option since tar 1.20. Starting in tar 1.22 -J (capital 'j') means --xz and not --lzma.
Comment by bwoodacre 174 weeks and 3 days ago
"

malekmustaq 11-19-2012 09:48 AM

Thank you jefro. I did not know that.
My tar version=1.26 the --lzma and -J options are already available. I have tried tarring with lzma, the resulting file cannot be stat by 'fileroller' while the resultant file of -J option is easily handled by the same GUI reader. Both results extracted by the same switch. I observe that --lzma switch is entered only after the file name tar -cf foo.tar.lz foo --lzma.

Thank you again.

jefro 11-19-2012 03:07 PM

I learn something new everyday here.

lleb 11-19-2012 03:24 PM

tar the file first like you normally would

Code:

tar cvjf /path/to/tarball.tar.bz2 -X /path/to/excludes.conf /path/of/file/directory/to/tar
note you do not need the excludes.conf, it is just there as an option if you want to tar portions of a directory

to encrypt you can use something as simple as this:

Code:

openssl des3 -a -salt -in /path/to/tarball.tar.bz2 -out /path/to/target/encrypted/tarball.tar.bz2.enc -pass pass:<password_here>
there ya go. do not forget the password or you will never get access to the encrypted tarball again.

you can also use && to combine that into one command line. so it will first make the tarball, then encrypt it.

Code:

tar cvjf /path/to/tarball.tar.bz2 -X /path/to/excludes.conf /path/of/file/directory/to/tar[ && openssl des3 -a -salt -in /path/to/tarball.tar.bz2 -out /path/to/target/encrypted/tarball.tar.bz2.enc -pass pass:<password_here>


All times are GMT -5. The time now is 06:16 AM.