[Samba] tip for smbpasswd -s

Nick Soracco nick at hrd-aerosystems.com
Mon Jun 27 22:40:40 GMT 2005

I had a little bit of trouble on my Redhat 9 system trying to get
smbpasswd to accept passwords on stdin so I can script it.  

All of the solutions I saw on the mailing list were of the general

(echo <pass>; echo <pass>) | smbpasswd -s <username>

For whatever reason, that didn't work for me.  (note: I'm not much of a
Bash programmer!)  What did however, is:

echo -n -e "$PASS1\n$PASS2" | smbpasswd -as $USERNAME

The -n switch tells echo not to add a trailing newline character, and
the -e switch tells it to interpret C-style escape characters, of which
\n is the carriage-return escape code.  This is also assuming $PASS1 is
identical to $PASS2.

Hope this helps someone!
Nick Soracco <nick at hrd-aerosystems.com>
HRD Aerosystems, Inc.

More information about the samba mailing list