This is an old topic but still useful.
This are my scripts to create and delete users in a simple samba installation for storing backups.
Tested on CentOS
Prepare directory and permissions
Run this commands on a terminal
sudo mkdir /backups
sudo mkdir /etc/samba/smb.conf.d
sudo groupadd sambashare
sudo chgrp sambashare /backups
sudo useradd -M -d /home/sadmin -s /usr/sbin/nologin -G sambashare sadmin
sudo smbpasswd -a sadmin
sudo smbpasswd -e sadmin
smb.conf
[global]
workgroup = TUAITI
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
include = /etc/samba/includes.conf
smbaddshare.sh
#!/bin/bash
USER=$1
if [ -z "$1" ]
then
echo "No username given"
exit 1
fi
useradd -M -d /backups/$USER -s /usr/sbin/nologin -G sambashare $USER
mkdir /backups/$USER
chown $USER:sambashare /backups/$USER
chmod 2770 /backups/$USER
smbpasswd -a $USER
smbpasswd -e $USER
cat /etc/samba/smb.conf.d/$USER.conf
[$USER]
path = /backups/$USER
browseable = no
read only = no
force create mode = 0660
force directory mode = 2770
valid users = $USER @sadmin
EOF
ls /etc/samba/smb.conf.d/* | sed -e 's/^/include = /' > /etc/samba/includes.conf
smbcontrol all reload-config
smbremoveshare.sh
#!/bin/bash
USER=$1
if [ -z "$1" ]
then
echo "No username given"
exit 1
fi
read -r -p "Are you sure you want to delete the user ? [y/N] " response
response=${response,,} # tolower
if [[ "$response" =~ ^(yes|y)$ ]]
then
smbpasswd -x $USER
userdel $USER
mv /backups/$USER /backups/$USER.`date +"%Y%m%d%H%M%S"`.deleted
rm /etc/samba/smb.conf.d/$USER.conf
ls /etc/samba/smb.conf.d/* | sed -e 's/^/include = /' > /etc/samba/includes.conf
smbcontrol all reload-config
else
echo "Nothing done"
fi