4

How do I pass a password to hdiutil attach?

I have an encrypted sparsebundle (test.sparsebundle) and it's password is "test", with no quotes.

I'd like to automate opening that file.

I have tried

echo "test" | hdiutil attach -stdinpass test.sparsebundle

and

echo test | hdiutil attach -stdinpass test.sparsebundle

But it returns

hdiutil: attach failed - Authentication error

6

Ah! A little more digging, and careful reading of the man page. I need a null terminated string.

So

printf '%s\0' 'test' | hdiutil attach test.sparsebundle -stdinpass

works.

  • 1
    If the password has no spaces or characters special to the shell it can be shortened to just: printf test|hdiutil attach test.sparsebundle -stdinpass – user3439894 Aug 2 '15 at 16:35
  • 1
    The \0 isn't actually needed, but using %s is a good idea -- there are a lot of "special characters" that can trip you up. – Gordon Davisson Aug 2 '15 at 17:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .