Prevent other users from ejecting (or even seeing) the mounted disk images

dmgfindermountprivacy

I have an encrypted disk image (sparsebundle) where all of my private documents are stored; I mount it to a custom mount point with:

mkdir -p /Users/gabriele/MyDocs
hdiutil attach /MyDocs.sparsebundle -mountpoint /Users/gabriele/MyDocs

Other users see the mounted disk image in the Finder window sidebar and maybe also on their Desktops (according to Finder preferences), but they cannot access the volume because of unsufficient privileges. In any case other users can eject the volume, and this is bad.

Is there a way to prevent other users from ejecting my volumes, or even seeing this volume if they don't have enough privileges to view its innards?

Best Answer

To help make the mounted disk image less visible, you can run the SetFile command to make the volume's directory invisible. This will make the mounted disk image be less-obviously visible in the Finder sidebar for other users. Of course, this makes it less visible to you, too, but you can make an alias in the Finder to where the folder should be for you.

Run SetFile to make the mounted disk image image be invisible in the Finder:

SetFile -a V /Users/gabriele/MyDocs

Open the disk image location in the Finder:

open /Users/gabriele/MyDocs

Make an alias to make it easy for you to open the now-hidden MyDocs. Within the open Finder window, grab the folder icon in the top center where it says "MyDocs" and then drag that while holding down the Option+Command keys and release it on your Desktop, just not to /Users/gabriele, because you will need to rename the alias first, otherwise it will not let you copy it. So rename the dragged-off "MyDoc" to "MyDoc alias", then move it to /Users/gabriele or wherever you like. Now you should have the alias "MyDoc alias" to your hidden MyDoc directory, other users will not see it in the Finder sidebar.

Note: Xcode needs to be installed in order to use SetFile. Additionally, I had to relaunch the Finder on Lion for the mounted disk image to become invisible, try that if you can't get MyDoc to disappear.

Not sure how to prevent ejection, since anyone with access to Disk Utility, the mount command, etc. can see the path to it and un-mount it for you. However, making it invisible does lessen the need to make it un-ejectable, since it will not be in other users' faces in the Finder as an option to eject.