While creating a bash script to automate the configuration of a vhost and wordpress installation, I needed to automatically create an ubuntu user and assign the password from within the script without ANY user interaction.
I tried many different methods to no avail; The only solution that worked for me was piping username:password into chpasswd:
- echo “$usrn:$usrpwd” | chpasswd
source: http://www.ibm.com/developerworks/aix/library/au-chpasspwgen.html

nice article, simple and work for me. Thanks ..
Not working…. Debian squeeze, bash
[root@cicolina bin]# echo “test:testpass” | chpasswd
[root@cicolina bin]# cat /etc/passwd | grep test
test:x:5060:100:here:/home/users/test:/bin/bash
[root@cicolina bin]#
Sorry, ma fault! I should have looked into /etc/shadow. It’s working, you can delete my previous post
Spent half a day trying everything I could find for this. This finally worked. Thanks bunches!