Perl code to generate Samba passwd hashes?

John D Blair jdblair at
Sat Aug 29 18:51:07 GMT 1998

Marlys Nelson wrote:
> Does anyone have perl code that can generate the Samba passwd hashes
> from a clear text password?
> I'm aware of the smbpasswd command that comes with Samba but that
> isn't the best tool for my purposes.  I have a local account
> creation/deletion software that already handles encypting the password
> to generate unix /etc/passwd files and I need to be able to do the
> same for the Samba passwd file as well.

I needed just such a perl module.  I explored creating a perl module,
but in the end opted to create a simple command-line tool called
'gethash'.  You put your password in the environmental var 'SMBPASSWD'
then run gethash.  It outputs the two password hashes on standard
output.  If you would like it I'll send you a patch file.

For example:

# export SMBPASSWD='mypasswd'
# gethash

Call this from perl, or any other scripting language for that matter, is


John D. Blair                                   jdblair at
Software Engineer, Cobalt Networks Inc.

More information about the samba mailing list