====== Batch Add Samba Users ====== First, this is a kludge, but it works. I've modified [[http://samba.2283325.n4.nabble.com/smbpasswd-batch-mode-td2421770.html]] to do things a little different. ===== create a user data file ===== This contains 7 fields separated by a colon (so, your password can not contain colons). The fields are - username - password - uid (empty means let sys generate) - gid (Primary Group ID, empty means create new group with username) - gecos (the thing few people use) - homedir - shell (we're setting to /bin/false so they can not log in from cli) mary:maryspw::100::/home/users/mary:/bin/false john:johnspw::100:/home/users/john:/bin/false ===== The Script ===== There are many ways of doing it. The following reads the data file, one line at a time. Each line is formatted exactly as the newusers command expects, so we just send it directly to the newusers command smbpasswd does not have a batch mode. It always requires you to enter the password from the cli, twice. So, we echo the password twice, then run smbpasswd. The last command dumps the binary samba database. If you have a system that still uses /etc/samba/smbpasswd to store credentials, it would likely fail. #!/bin/bash datafile=userdata line_count=`cat $datafile | wc -l` mkdir -p /home/users for data in `seq $line_count` do read data # create the user ( echo $data ) | newusers #/usr/sbin/adduser -m -s /bin/false -p $password $username # for smbpasswd username=`echo $data | awk -F":" '{print $1}'` password=`echo $data | awk -F":" '{print $2}'` (echo $password; echo $password) | /usr/bin/smbpasswd -s -a $username #/bin/chmod 700 /home/$username done < "$datafile" # dump the samba database pdbedit -L ===== Links ===== * [[https://superuser.com/questions/271034/list-samba-users]] * [[http://samba.2283325.n4.nabble.com/smbpasswd-batch-mode-td2421770.html]]