openssl passwd -crypt -salt /s myNewPasswd
The password can only be eight characters long; anything longer will be truncated. I don't know if the salt has to stay the same or not, but to be safe, I just used the same salt as the original password. I doubt this makes any difference, though.
I ssh'd to the iPhone, and ran cat /etc/master.passwd, then copied that output to BBEdit (or other text editor). Then I replaced the passwd section (in between the first two colons) with my new hash for both root and mobile users. Finally, I copied the whole thing, switched back to the iPhone's ssh session and ran:
cat > /etc/master.passwd
I then pasted in the clipboard contents and pressed Command-D. That's it; the password was changed. I ran through most of my apps, put the iPhone to sleep, woke it up, and rebooted all without any problems. You don't need to reboot or do anything else for this to take effect.
[robg adds: I haven't tested this one.]

