Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 46 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


 % 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.

share|improve this answer
For anyone wondering how to decrypt the file with openssl: openssl aes-256-cbc -d -in out.tar.gz.enc -out decrypted.tar.gz –  nathan.f77 Jan 28 '13 at 22:03
@nathan.f77 that command also shows how to do things without piping them into openssl. openssl enc -aes-256-cbc -e -in foo.tar.gz -out bar.tar.gz.enc –  Keith Smiley Mar 6 at 23:48
add comment

If your intent is to just password protect files, then use the hand zip utility through command line

zip -e <file_name>.zip <list_of_files>

-e asks the zip utility to encrypt the files mentioned in

Working example:

$ touch file_{0,1}.txt # creates blank files file_0 & file_1    
$ zip -e file.zip file_* # ask zip to encrypt
$ ls file*
share|improve this answer
add comment

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.

share|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
Just like the man says, -r. –  Ignacio Vazquez-Abrams Jul 12 '10 at 13:24
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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