Skip to content

Instantly share code, notes, and snippets.

@RogerCreasy
Created August 3, 2016 13:13
Show Gist options
  • Save RogerCreasy/fb55ad1c6b8994990c1b9043581ec33e to your computer and use it in GitHub Desktop.
Save RogerCreasy/fb55ad1c6b8994990c1b9043581ec33e to your computer and use it in GitHub Desktop.
Add Samba User
#!/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="/home/names.txt"
cat ${NEW_USERS} | \
while read USER GROUP SMBPASS ; do
groupadd ${GROUP} 2> /dev/null
adduser ${USER} -g ${GROUP}
(echo $SMBPASS; echo $SMBPASS) | passwd --stdin ${USER} > /dev/null
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment