Creating MD5 printable hashes for the shadow file from a script

Jurjen Bokma

May 2009

If the cleartext password is known (e.g. when generating temporary student accounts), the printable hash to go in /etc/shadow can be generated like this: USERSHADOW=$(perl -e "use Crypt::PasswdMD5; print unix_md5_crypt(${USERPASSWD}, $(( ${RANDOM} % 4096)) );")


Of course, ${RANDOM} works because we are using a bash shell, ${USERPASSWD} is the clear text, and the Debian package libcrypt-passwdmd5-perl has to be installed.