Chinaunix首页 | 论坛 | 博客
  • 博客访问: 105299
  • 博文数量: 23
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 235
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-19 22:44
文章分类

全部博文(23)

文章存档

2011年(1)

2008年(1)

2007年(21)

我的朋友
最近访客

分类: LINUX

2007-06-29 17:54:44

这2天接了个linux下文件服务器的单,所以研究samba,目前能做到的是批量导入用户,有些方面的处理还不是很周到,以后有时间再改,先发上几个相关文件.
安装执行办法:
./update.sh remove
./update.sh install
设置smb
./update.sh set
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 < /etc/passwd

    while read name passwd
    do
     deluser $name
        useradd -g kx -k /dev/null -p $passwd -m -s /bin/false -d /home/$name $name >& /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 =======================
[homes]
   comment = Home Directories
   browseable = no
   writable = yes
   create mask = 0700
   directory mask = 0700
   valid users = %S
[wind]
   comment = wind
   path = /home/wind
   writable = yes
   create mask = 0770
   directory mask = 0770
[tools]
   comment = tools
   path = /home/tools
   writeable = yes
   create mask = 0700
   directory mask = 0700

; write list = root, @ntadmin
; postexec = /bin/umount /cdrom




user.txt

kx1:0
kx2:0
kx3:0
kx4:0

阅读(2183) | 评论(0) | 转发(0) |
0

上一篇:timer linux编程

下一篇:unlikely和likely

给主人留下些什么吧!~~