I want to compress several files and encrypt them with a password if possible.
- Are there any build-in tools in Mac OS that provide such functionality?
- If not, can you recommend me a (freeware) alternative?
- I'd also be happy with a terminal command.
Yes, you can do this using the built-in Disk Images of Mac OS X. A disk image (or DMG file) is a file which, when opened, presents itself as a removable Mac OS X volume, similar to a removable hard drive. Many OS X applications are deployed on disk images. If you encrypt your home directory using FileVault, you're creating a spare bundle disk image.
You can create OS X disk images which are compressed and/or encrypted. However, if you create a compressed DMG, it will be read-only, so that may or may not work for you.
To create a new, empty encrypted disk image in OS X:
After you save the disk image file, you'll be prompted for a password and verification. Once completed, you'll have a new volume on your desktop and in the "Computer" view where you can begin dropping files!
To create a compressed, read-only image, you can do one of two things:
Protip: if you drag and drop a folder onto Disk Utility's dock icon it will automatically offer to create a disk image out of that folder.
Protip #2: If you create an encrypted disk image out of an unencrypted folder and you want to delete the original, unencrypted files, remember to use secure erase otherwise you risk leaving confidential information on your hard drive.
Jason Seney explains in his article Open, Edit & Save Encrypted Files with Vim and GPG:
Using MacGP2 you can encrypt:
Jason's article provides instructions to pipe files directly in and out of vim and the secret sauce for creating alias commands that make encrypting and decrypting easy.
As I said, I make use of the built-in DMG tools, but if you're a command line user, particularly of vim, or if you need to insure that plaintext copies of your secret files never exist on disk or in swap files, Jason's method is worth considering.
The easiest way to compress is to just right-click any file and select the appropriate option to create a zip file (without password though).
On command-line/Terminal level there are at least
For zip and openssl the password will be visible to all users while the encryption is running. This is usually not a problem on a desktop system, otherwise you may consult the
You can do this with just tools in OSX
For simple compression right click on the file in Finder and choose compress..
To compress and add a password - With Disk Utility create a new disk image - choosing the Encryption and Image format options. Then copy the files into it.
From the command line look at gzip and zip