Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like a program that would exist on my flash drive that, when run, would

  • open an encrypted disk image with a stored password
  • then change the password to a random number
  • store it for using it the next time

Can this be done?

share|improve this question
As this is related to your previous question, I edited out the part about what you are asking here. – slhck Jul 29 '11 at 10:26
This will be fun once storing the password fails for some reason. – Daniel Beck Jul 29 '11 at 10:45
up vote 5 down vote accepted

If you know shell script, you can write s simple program that does that. Use hdiutil to change an encrypted disk password:

hdiutil chpass [image_name]

It will interactively ask you for your previous password and new password so you have to use some pipes or maybe expect. To generate a random number, echo $RANDOM should do. To store the passwords you can use a simple text file, if you don't mind keeping it unprotected.

share|improve this answer
Thanks! What's a tube? – JShoe Jul 29 '11 at 5:56
It's not a tube, it's a pipe. hdiutil expects that you enter your passwords manually. If you want to automate this process you should use expect. Take a look at some Wikipedia examples: – nmat Jul 30 '11 at 3:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.