I did have a hard time looking for information regarding linux scripts that adds new samba users (many users) so I decided to log the script I made to add new samba users. I tried to use the method that some sites suggested that copies the /etc/passwd to /etc/samba/smbpasswd via cat < /etc/passwd | makesmbpasswd.sh > /etc/samba/smbpasswd, but this does not work. By the way, I'm using Samba 3.025d under OpenSuse 10.2
So i tried to figure it out by conducting a trial and error 'experiments'
and luckily I did it. The things I've done are the following:
First I add 1000 UNIX users using the following scripts (unixusers.sh)
#—————————————————————————————————–
# Script: unixusers.sh - use for creating 1000 users by Felix
#I declare 100 unique passwords in an array
declare apasswords[100]
apasswords[0]="password1"
apasswords[1]="pasword2"
apasswords[1]="… and so on… up to 100 unique passwords'
n=0
for ((i=1;i<=1000;i++))
do
echo "user$i = ${apasswords[n]}" >> mypasswords.txt
cuser="user$i"
cpassword="${apasswords[n]}"
echo "Wait creating user $cuser = $cpassword, please wait…"
useradd $cuser -p $cpassword
n=`expr $n + 1`
if test $n -gt 100
then
n=0
fi
done
#—————— unixusers.sh ends here ———————————-
The unixusers.sh script will create 1000 UNIX users with passwords.User ids and passwords are saved inside a text file name: mypasswords.txt, if in case you want to have print-out of the users and passwords.
Now, the following is the script that adds the 1000 UNIX users to SAMBA (/etc/samba/smbpasswd)
#—————————————————————————————————–
# Script: sambausers.sh - use for creating 1000 SMB users by Felix
#I declare 100 unique passwords in an array the same as the passwords on unixusers.sh
declare apasswords[100]
apasswords[0]="password1"
apasswords[1]="pasword2"
apasswords[1]="… and so on… up to 100 unique passwords'
n=0
for ((i=1;i<=1000;i++))
do
rm temp.txt
echo "${apasswords[n]}" >> temp.txt
echo "${apasswords[n]}" >> temp.txt
cuser="user$i"
cpassword="${apasswords[n]}"
echo "Wait creating user $cuser = $cpassword, please wait…"
smbpasswd -a $cuser -s < temp.txt
n=`expr $n + 1`
if test $n -gt 100
then
n=0
fi
done
#—————— sambausers.sh ends here ———————————-
That's all folks! A script that adds new samba users (for SAMBA 3.025d in openSUSE 10.2).