LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2012, 02:36 AM   #1
rakrr786
Member
 
Registered: May 2012
Posts: 34

Rep: Reputation: Disabled
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
 
Old 11-18-2012, 02:46 AM   #2
Elv13
Member
 
Registered: Apr 2006
Location: Montreal,Quebec
Distribution: Gentoo
Posts: 825

Rep: Reputation: 129Reputation: 129
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.
 
1 members found this post helpful.
Old 11-18-2012, 03:24 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
1 members found this post helpful.
Old 11-18-2012, 04:23 AM   #4
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,669

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
Quote:
Originally Posted by rakrr786 View Post
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.

Last edited by malekmustaq; 11-18-2012 at 04:24 AM.
 
Old 11-18-2012, 12:26 PM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
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
"
 
1 members found this post helpful.
Old 11-19-2012, 09:48 AM   #6
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,669

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
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.
 
Old 11-19-2012, 03:07 PM   #7
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
I learn something new everyday here.
 
Old 11-19-2012, 03:24 PM   #8
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Utilizing multi core for tar+gzip/bzip compression/decompression galapogos Linux - Software 13 10-07-2013 01:44 AM
[SOLVED] Using tar to create bzip file linuxguy7820 Linux - Newbie 5 05-19-2011 08:48 PM
is checksum necessary for tar, gzip, zip? carolus Linux - General 1 08-23-2009 07:01 PM
tar and bzip extract from CD phenrichs Linux - Newbie 4 12-05-2007 05:44 PM
backup: dump vs tar-bzip/gzip kpachopoulos Linux - General 2 12-21-2006 06:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration