user.txt为用户密码文件,user:password
update.sh
#!/bin/bash
if [ "$1" = "remove" ]; then
aptitude purge samba -y > /dev/null
apt-get remove samba* -y > /dev/null
rm -rf /etc/samba > /dev/null
elif
[ "$1" = "install" ]; then
echo "Waiting..................."
aptitude install samba -f -y
aptitude install winbind -f -y
aptitude install expect -y
addgroup kx
elif
[ "$1" = "set" ]; then
/etc/init.d/samba stop
cp ./smb.conf /etc/samba/smb.conf -f
SAVEDIFS=$IFS
IFS=:
while read xname other
do
smbpasswd -x $xname
done & /dev/null
chown $name.kx /home/$name
./expect_smb.sh $name $passwd > /dev/null
echo "Add user ##$name## with password ##$passwd## over!"
done < ./user.txt
/etc/init.d/samba restart
fi
./expect_smb.sh
#!/usr/bin/expect -f
#FileName:expect_smb.sh
#Add user to the samba server
# 1---The name of user
# 2---The passwd of user
set username [lindex $argv 0]
set password [lindex $argv 1]
spawn smbpasswd -a $username
expect "*password:"
send "$password\n"
expect "*password:"
send "$password\n"
expect eof
smb.conf
[global]
workgroup = mygroup
server string = %h server
; wins support = no
; wins server = w.x.y.z
dns proxy = no
; name resolve order = lmhosts host wins bcast
; interfaces = 127.0.0.0/8 eth0
; bind interfaces only = true
log file = /var/log/samba/log.%m
max log size = 1000
; syslog only = no
syslog = 0
panic action = /usr/share/samba/panic-action %d
security = user
encrypt passwords = true
passdb backend = tdbsam
obey pam restrictions = yes
invalid users = root
; unix password sync = no
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n *password\supdated\ssuccessfully* .
; pam password change = no
domain logons = no
; logon path = \\%N\profiles\%U
; logon path = \\%N\%U\profile
; logon drive = H:
; logon home = \\%N\%U
; logon script = logon.cmd
; add user script = /usr/sbin/adduser --quiet --disabled-password --gecos "" %u
load printers = no
; printing = bsd
; printcap name = /etc/printcap
; printing = cups
; printcap name = cups
; printer admin = @ntadmin
; include = /home/samba/etc/smb.conf.%m
# You may want to add the following on a Linux system:
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
; domain master = auto
; idmap uid = 10000-20000
; idmap gid = 10000-20000
; template shell = /bin/bash
winbind enum groups = yes
; winbind enum users = yes
#======================= Share Definitions =======================