Shell Script to create samba users in bulks

If you want to crate so many numbers of users at once, then you can do that by running the given shell script.

*********************************
#!/bin/bash
#
# Ensure that root is running the script.
##
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
echo "You must be root to add news users!"
exit 1
fi
#
clear
NEW_USERS="/root/names.txt"
echo "Enter password you want to set for all users:"
read SMBPASS
cat $NEW_USERS | while read USER; do
#adduser $USER `echo $SMBPASS`; `echo $SMBPASS` | passwd --stdin $USER > /dev/null
adduser $USER -p $SMBPASS
echo Added user $USER
smbpasswd -e $USER -w $SMBPASS > /dev/null
(echo $SMBPASS; echo $SMBPASS) | smbpasswd -as $USER
echo -e "$USER = $USER" >> /etc/samba/smbusers
done
*********************************

Here in this script, you will have to give name of the users in /root/names.txt file line by line.
For Ex:
********
alpesh
keyur
ashish
********

Once you run this script, it will ask you for the password which you want to assign for each users.

I hope this will help you.

No comments:

Post a Comment