Create an Encrypted Disk Image with hdiutil

Build an AES-256 encrypted .dmg vault from the Terminal — no Disk Utility clicking required.

macOShdiutilsecuritydisk-imageencryptionLow risk
Run `hdiutil create -size 500m -fs APFS -encryption AES-256 -stdinpass ~/SecureVault.dmg`, then type your password when prompted.

01Command

Command
$ hdiutil create -size 500m -fs APFS -encryption AES-256 -stdinpass ~/SecureVault.dmg

02What it does

hdiutil is the command-line engine behind Disk Utility, and it can script the whole encrypted-vault workflow: -stdinpass reads the password so it never lands in shell history or ps output. When double-clicked, the resulting .dmg asks for the password before mounting. Use -srcfolder to add content at creation time, or grow the image later with `hdiutil resize`.

03Risk

RiskLow risk

04Undo

Undo
$ hdiutil detach /Volumes/SecureVault && rm ~/SecureVault.dmg

05Sources

Last verified: 2026-09-17 · Category: System & Settings

06Related solutions