I want to create some tar.gz (and possibly tar.bz2) files, using the tar command on Ubuntu 10.04.

I want to password protect the file.

What is the command to do this (I have Googled, but found nothing that shows how to create and extract compressed files using a password).

Anyone knows how to do this?

link|improve this question

70% accept rate
feedback

2 Answers

up vote 13 down vote accepted

you have to apply the unix-philosophy to this task: one tool for each task.

tarring and compression is a job for tar and gzip or bzip2, crypto is a job for either gpg or openssl:

 % tar cz folder_to_encrypt | openssl enc -aes-256-cbc -e > out.tar.gz.enc

or

 % gpg --encrypt out.tar.gz

the openssl-variant uses symetric encryption, you would have to tell the receiving party about the used 'password' (aka 'the key'). the gpg-variant uses a combination of symetric and asymetric encryption, you use the key of the receiving party (which means that you do not have to tell any password involved to anyone) to create a session key and crypt the content with that key.

if you go the zip (or 7z) route: essentially that is the same as the openssl-variant, you have to tell the receiving party about the password.

link|improve this answer
feedback

Neither tar, gzip, nor bzip2 supports password protection. Either use a compression format that does, such as zip, or encrypt it with another tool such as GnuPG.

link|improve this answer
Ah, that explains why I couldn't find anything online. I think I'll go for zip. – morpheous Jul 12 '10 at 13:01
Gah!, I'm trying to recursively zip a directory with passwors, and it only creates a zip file with the name foobar as an (empty) directory in it. Here is the command I am using: zip -e foobar.zip foobar. foobar is a non-empty folder in the current directory – morpheous Jul 12 '10 at 13:22
2  
Just like the man says, -r. – Ignacio Vazquez-Abrams Jul 12 '10 at 13:24
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.