Compress, encrypt, and copy data to offsite server #

Under Windows, I was using AxCrypt and WinSCP from the context menu to compress, encrypt, and send data to an offsite server. Under OS X, I am now using a simple bash command list to achieve the same thing faster and with greater compression:

$ /Applications/file/BetterZip.app/Contents/Resources/7z a -mx9 -pSECRET -mhe ~/Desktop/file.7z ~/Documents/file.ext && scp -P 2012 ~/Desktop/file.7z [email protected]:/home/ && rm ~/Desktop/file.7z

Let's break down what's happening here:
  1. /Applications/file/BetterZip.app/Contents/Resources/7z Call the 7-Zip file archiver contained in BetterZip (which I happened to have from a MacUpdate Promo Bundle). There are several other Mac binaries available or you can download and compile from source.
  2. a Add file(s) to archive
  3. -mx9 Maximum ("Ultra") compression
  4. -pSECRET Set password to SECRET
  5. -mhe Encrypt archive headers (i.e., filenames will be encrypted also)
  6. ~/Desktop/file.7z Name of archive to create or add files to
  7. ~/Documents/file.ext File to compress and encrypt
  1. && Execute next command only if previous command returns an exit status of zero (i.e., wait for command to complete successfully before proceeding)
The next section assumes public-key authentication has been configured (see part 2 of Hardening SSH and Mounting Remote Filesystem in OS X Finder via SSHFS for more information):
  1. scp Secure copy command
  2. -P 2012 Connect via port 2012
  3. ~/Desktop/file.7z Local file to copy
  4. [email protected]:/home/ Remote username and domain followed by directory where file will be copied to
These next two steps are optional:
  1. && Execute next command only if previous command returns an exit status of zero (i.e., wait for command to complete successfully before proceeding)
  1. rm ~/Desktop/file.7z Delete 7z archive from local computer
Notes:

/mac | Sep 19, 2009


Subscribe or visit the archives.