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.

Hey guys I was wondering how would I gzip 7z tar or just regular zip a directory like this /var/Backups/Tones regular gzip won't do it because Tones is a directory and this site ss64.com/bash doesn't really tell much and I've searched google but what those people are talking about is computer based not mobile and I'd like to also make the archive password protected if its possible? If it helps any I'm using bash to do this.

This will be used on an iDevice like iPad iPhone and iPod when jailbroken; they have 7z gzip and tar.

Ok I got the compression for the directory to work using this:

#!/bin/bash
cd /var/Backups
7z a -p{example} Tones.tar.7z

My problem now is when I go to extract that archive on my iPhone it doesn't even ask for a password am I doing something wrong?

share|improve this question
add comment

migrated from stackoverflow.com Jul 4 '12 at 7:38

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

2 Answers

tar czf your_dir.tgz your_dir/ will create a compressed archive that most other zip programs can at least understand and unpack if you need to.

For password protection, though, there is no direct support in tar/gzip. Use the solution proposed by ghoti, or set up GPG/PGP and encrypt the tar before compressing it.

share|improve this answer
    
How would I password protect the archive? –  Kevin Nye Jul 3 '12 at 15:17
    
I think I did this wrong tar cxf /var/Backups/Tones.tgz /var/Backups/Tones/ –  Kevin Nye Jul 3 '12 at 15:23
    
Nope, I did it wrong. Replace the 'x' in the command with a 'z'. Edited above. –  Jochen Jul 3 '12 at 15:24
    
Well it will be used on an iDevice like iPad iPhone and iPod when jailbroken they have 7z gzip and tar –  Kevin Nye Jul 3 '12 at 15:25
1  
He said tar/gzip or 7z, and tar compression uses gzip's algorithm. –  Jochen Jul 3 '12 at 15:25
show 12 more comments

You've got various options.

7z

tar -cf tarfile.tar path/to/files/
7z a tarfile.tar.7z tarfile.tar

This would create tarfile.tar.7z. To help with clean-up, if you have it installed, you might use:

p7zip tarfile.tar

instead.

As for password protection, that is an option neither of tar nor p7zip. If you're comfortable using the 7z command, you can give it a -p{password} option, according to the man page.

7z a -p{password} tarfile.tar.7z tarfile.tar

This leaves tarfile.tar in place, so you'll need to clean up with something like:

if 7z q -p{password} tarfile.tar.7z tarfile.tar; then
  rm tarfile.tar
fi

A simpler option may be to compromise on your compression, and just use ZIP with the -9 option for the most compression it can muster.

Note that this isn't nearly as secure as a properly designed scheme using PGP or GnuPG, so if you can figure out that method (and the complexity doesn't compromise your security), you'll be further ahead. Read about PGP or GnuPG, both of which will do what you need.

gzip

Like 7z, you won't be able to password-protect your tar with a single command line. Further, the gzip command also doesn't provide any password protection. So this also forces you to use a second step:

tar czf - path/to/files/ | openssl enc -aes-256-cbc -e > tarfile.tar.gz.enc

Read the documentation for openssl to find out how to get it not to ask for a password on the command line. Or:

tar czf tarfile.tar.gz path/to/files/
gpg --encrypt tarfile.tar.gz

Note that you'll need to set up gpg before this will work.

There may be (or "there certainly are") other ways to do this. You may wish to treat this as a starting point for further research of your own.

zip

If the zip command is included in your jailbroken iDevice, then you can use a command like:

zip -e -P{password} zipfile.zip path/to/files/

Note that the man page for zip says of the -P option: THIS IS INSECURE. It goes on to say, where security is truly important, use strong encryption such as Pretty Good Privacy instead of the relatively weak standard encryption provided by zipfile utilities.

Any of these commands can be placed in a script. If you want help writing the script, please post what you've got so far, so we can provide feedback.

That's all I've got.

share|improve this answer
    
7z uses AES encryption with SHA-256 x 2^19 key. How is that not "properly designed scheme"? –  Oleg V. Volkov Jul 3 '12 at 15:25
    
7z is fine. It's the stuff wrapped around it that is almost certainly broken. A shared-key approach requires that the password be distributed (or at least stored on the same system that will read the logs), which may be riskier than a public-key based solution with PGP. –  ghoti Jul 3 '12 at 15:36
    
Do I need a separate file with a command line to get this to work? –  Kevin Nye Jul 3 '12 at 15:44
    
I'm using an iPhone my script will be used with an iPad and iPod as well –  Kevin Nye Jul 3 '12 at 15:58
1  
I suspect that you already have a number of working solutions, but you're implementing them badly. For example, you should always quote words that contain special characters. Your shell may interpret some characters in ways you don't expect, despite quoting (for example, ! in tcsh). Since you haven't told us your shell, we can't help you there. But just as a start, are you including curly braces in your password? You realize that {password} in the example code means that your password starts at the open curly brace and ends at the close? –  ghoti Jul 4 '12 at 2:33
show 4 more comments

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.