Skip to content

Instantly share code, notes, and snippets.

@mrrooijen
Last active January 2, 2016 22:59
Show Gist options
  • Save mrrooijen/8373255 to your computer and use it in GitHub Desktop.
Save mrrooijen/8373255 to your computer and use it in GitHub Desktop.
Set of commands for creating OSX Journaled (Extended) Encrypted images. Attaching them. Detaching them. Attaching them on system boot.
# Create a 10 megabytes, blank, AES 256 Encrypted, with password "mypassword",
# MacOS Journaled (Extended) image named "MyImage" when attached,
# and myimage.dmg as filename in the current directory.
#
echo -n "mypassword" | hdiutil create \
-encryption AES-256 \
-stdinpass \
-size 10m \
-fs "Journaled HFS+" \
-volname MyImage \
./myimage.dmg
# Attaches (Mounts) the ./myimage.dmg to /Volumes/MyImage
#
echo -n "mypassword" | hdiutil attach -stdinpass ./myimage.dmg
# Flags the /Volumes/MyImage volume as hidden so it doesn't show up on the Desktop.
#
chflags hidden /Volumes/MyImage
# Detaches (Unmounts) the MyImage Volume.
#
hdiutil detach /Volumes/MyImage
# Mounts the image on system boot.
#
crontab -e # (Opens Crontab Buffer) Add the following line:
@reboot /bin/bash -c 'echo -n "mypassword" | hdiutil attach -stdinpass /path/to/myimage.dmg'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment