On Mac OS X, right now I use the following to back up a small project folder to a USB Flash drive:

alias a='alias'
a dateseq='date "+%Y-%m-%d %H:%M:%S"'
a backup_proj='cp -a ~/code/MyProj "/Volumes/KINGSTON/MyProj `dateseq`"

so each time I type backup_proj, the folder is backed up from the hard drive to the USB drive, and each project is also internally version controlled using Git. Each folder is only about 500kb so it takes a long time to even fill up 1GB (the Flash Drive is 16GB). The folder is backed up as:

$ ls -1 /Volumes/KINGSTON/
MyProj 2012-05-27 08:20:50/
MyProj 2012-05-27 10:27:56/
MyProj 2012-05-27 14:53:01/

But I get paranoid and also want to back up to Google Drive or Dropbox so it will get uploaded to their server automatically, just by encrypting the whole folder and copying the single resulting file to Google Drive or DropBox's folder, and the password can be apple234321pineapple and specified on the command line. I wonder what is a good way to encrypt the folder into a single file so that it takes a non-practical time to crack? (can you please give the command line that will do it).


man zip

From the man page:

-e --encrypt Encrypt the contents of the zip archive using a password which is entered on the terminal in response to a prompt (this will not be echoed; if standard error is not a tty, zip will exit with an error). The password prompt is repeated to save the user from typing errors.

Another option is SSL encryption, example:

openssl des3 -salt -pass pass:password -in file.txt -out encfile.txt

Maybe you can TAR the folder before using openssl to encrypt it.

man openssl

  • you mean I have to type a password every time? Also, with zip, it seems that the filenames are visible even if no password is provided – 太極者無極而生 May 29 '12 at 21:00
  • @動靜能量 see the update, using a combination of tar and openssl you should be able to automate the password input process. The openssl command excepts many forms of input. – Tim May 30 '12 at 13:27
  • By the way, I found that on Mac OS X, I can use a password on the command line: zip -P foobar -r myproj.zip MyProj I know it is less secure but I think the chance of my Google Drive being hacked and my bash history being hacked at the same time is kind of slim – 太極者無極而生 Jun 1 '12 at 12:37
  • 1
    +1 for OpenSSL cli fu, although I discourage using -pass pass:password as other non-privileged users can see the password in ps (and others). Better to use -pass env:var or -pass stdin. – bahamat Jul 2 '12 at 18:44

If you use gpg, then you can bundle and encrypt on the fly, without having to specify a password.

% tar cf - MyProj | gpg -e -u 01234567 >/tmp/backup.tar.gpg

Here, 01234567 is the keyid of the key you want to use to decrypt the backup. If, in your ~/.gnupg/gpg.conf, you set the default-key parameter to the keyid of your preferred key, then you can omit the -u option.

You can similarly zip to stdout with zip - MyProj.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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