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'm using the Unix tar command as follows to tar up a directory and its files:

tar cvzf fileToTar.tgz directoryToTar

Is there a way to password protect the .tgz file? I've created password-protected ZIP files on Windows so I would assume Unix has the same capability. Any ideas?

share|improve this question

migrated from stackoverflow.com Dec 21 '11 at 21:00

This question came from our site for professional and enthusiast programmers.

add comment

4 Answers 4

up vote 6 down vote accepted

Use crypt or gpg on the file.

share|improve this answer
4  
A simple example within the answer would be more helpful. –  mtk Jun 20 '12 at 8:07
1  
If you click the blue-ish text in my answer that says "crypt" or "gpg", your browser will display simple examples for you. –  Christopher Neylan Jun 20 '12 at 14:40
4  
a simple example would have been suffice instead of wasting out time clicking on something. –  duckx Jan 24 at 4:18
add comment

Neither the tar format nor the gz format has built-in support for password-protecting files.

The Windows zip format combines several different piece of functionality: compression (e.g. gzip), archiving multiple files into one (e.g. tar), encryption (e.g. gnupg), and probably others. Unix tends to have individual tools, each of which does one thing well, and lets you combine them.

The Unix equivalent of a password-protected .zip file would probably be called something like foo.tar.gz.gpg or foo.tgz.gpg.

And there are open-source zip and unzip tools for Unix, though they may not provide all the capabilities of the Windows versions (I'm fairly sure the newer .zipx format isn't supported).

share|improve this answer
add comment

You can use command:

zip -P password file.zip file

Or better:

zip -e file.zip file

man zip
share|improve this answer
add comment

You can use ccrypt.

Things can be encrypted by a pipe:

tar cvvjf - /path/to/files | ccrypt > backup.tar.bz2.cpt

Or in place:

ccrypt backup.tar.bz2

For automating, you can save a passkey into a file and use this passkey to encrypt:

ccrypt -k ~/.passkey backup.tar.bz2
share|improve this answer
add comment

Your Answer

 
discard

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.