======都是以前写的档,好多都丢了,今无意中找来几个全放出来,放出以便后参考======
CentOS4.4平台下搭建Samba服务器笔记V1.0
                                                                                           ------Weihu.Yan 2008.5.26----
1.       系统简介:
最简安装!(development tool及兼容工具包)
 
检查是否有以下几个包:
[root@extmail tmp]# rpm -qa | grep samba  ##看到只安装了以下两个包,所以还得安##
samba-common-3.0.10-1.4E.9
samba-client-3.0.10-1.4E.9
[root@extmail tmp]# rpm -ivh /root/samba-3.0.10-1.4E.9.i386.rpm
警告:/root/samba-3.0.10-1.4E.9.i386.rpm: V3 DSA 簽章:NOKEY, key ID 443e1821
準備中...                   ########################################### [100%]
   1:samba                  ########################################### [100%]
[root@extmail tmp]# rpm -ivh /root/rsync-2.6.3-1.i386.rpm  ###此包为了方便备分之用##
警告:/root/rsync-2.6.3-1.i386.rpm: V3 DSA 簽章:NOKEY, key ID 443e1821
準備中...                   ########################################### [100%]
        已經安裝 rsync-2.6.3-1 套件
 
2.       开始配置smb.conf文件:
[root@extmail tmp]# vi /etc/samba/smb.conf
[global] 
workgroup = SAMBAGROUP   ####工作组名######
hosts allow = 10.
security = user
samba有四种安全等级:
share:用户不需要账户及密码即可登录samba服务器
user
:由提供服务的samba服务器负责检查账户及密码(默认)
server
:检查账户及密码的工作由另一台windowssamba服务器负责
domain
:指定windows域控制服务器来验证用户的账户及密码)
 encrypt passwords = yes     #######取消提注释#####
 smb passwd file = /etc/samba/smbpasswd     #######取消提注释#####
 
3.       创建共享,smb.conf文件结尾添加:
[samba]
comment = This is my samba server
path = /samba
writable =  yes
browseable = yes
read only = yes
create mode = 0664
directory mode = 0777
   检查配置文件的正确性
       [root@extmail tmp]# testparm
Load smb config files from /etc/samba/smb.conf
Processing section "[homes]"
Processing section "[printers]"
Processing section "[samba]"
Loaded services file OK.
 
4.       修改防火墙开放文件共享端口:
[root@extmail tmp]# vi /etc/sysconfig/iptables  ####实际测试,好像只开445即可###
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 137 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 138 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
[root@extmail tmp]# service iptables restart
清除防火墙规则:                                           [  确定  ]
chains 设置为 ACCEPT 策略:filter                       [  确定  ]
正在卸载 Iiptables 模块:                                  [  确定  ]
应用 iptables 防火墙规则:                                 [  确定  ]
[root@extmail tmp]#
 
5.       新建一个系统账户:
[root@extmail ~]# adduser leeki -s /sbin/nologin
[root@extmail ~]# passwd leeki
Changing password for user leeki.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
 
6.       然后创建samba账户
[root@extmail ~]# smbpasswd -a leeki  ###### -a是必须加的, 为了生成密码文件smbpasswd,该密码是windows登陆Linuxsamba用户密码######
New SMB password:
Retype new SMB password:
Added user leeki.
[root@extmail ~]# more /etc/samba/smbpasswd  ####查看生成的用户名与密码#######
7.       重启一下smb服务,开始测试吧!
[root@extmail /]# service smb restart
关闭 SMB 服务:                                            [  确定  ]
关闭 NMB 服务:                                            [  确定  ]
启动 SMB 服务:                                            [  确定  ]
启动 NMB 服务:                                            [  确定  ]
 
 
8.       相关参数介绍:
常用参数:
    comment :        
目录说明
    path :            
目录路径
    public            
开放共享 默认为no , 如果=yes 表示无需身份验证
    browseable:      
显示共享名称。
    valid users:      
允许列表中的用户访问
    read only:        
默认为yes,共享目录只读
    writable:         writable =no
read only = yes 一样的效果
    write list:          
如果前面只读,只有在此里面的用户才有写的权利
    creat mask:      
指定在共享目录里面建立文件的权限, 权限最高只能为 766
    directory mask:  
指定建立目录的权限
    force user:        
指定存取的用户张号
    force group
    指定用户存取组
9.    测试吧!
a.    建立一个PUBLIC,可读可写:
[root@extmail ~]# mkdir -p /public
[public]
Comment = public server
path = /public
public = yes
writable = yes
browseable = yes
b.       建立一个PRI,只有samba才可写:
[pri]
comment = pri file
path = /pri
public = no
write list = samba  #####表示只有samba用户才可以写,并且确定/pri文件夹samba有写的权利才可以这一点比较重要,samba对系统账户及smb账户分的很细#####
browseable = yes
c.       还是类似b,修改如下:
[pri]
comment = pri file
path = /pri
public = no
valid users = samba  ######加上这一行,表示,只有用samba用户登录的,才能看打开/pri的共享文件夹,用其它用户登录的只能看到,无法访问#####
write list = samba  ###如果/pri文件夹,samba无权限,虽此处有写的权限,但仍无法创建文件夹#####
browseable = yes
d.       来个复杂点的:
有个四个部分文件夹:techsalepublic
有如下用户:tech01,tech02,techman
            Sale01,sale02,saleman
                      Boss
有如下用户组:manager,tech,sale三个组:
Tech组含:tech01,tech02,techman
Sale组含:sale01,sale02,saleman
Manager组含:boss,saleman,techman
要求做到:manager组中的人员能够看到所有文件夹,但只能对本部分的文件夹有写权限,除了BOSS外,可以对任何文件夹进行写删操作!public任何人都可以写删操作!
[root@extmail ~]# groupadd tech
[root@extmail ~]# groupadd sale
[root@extmail ~]# groupadd fina
[root@extmail ~]# adduser tech01 -s /sbin/nologin
[root@extmail ~]# adduser tech02 -s /sbin/nologin
[root@extmail ~]# adduser techman -s /sbin/nologin
[root@extmail ~]# adduser sale01 -s /sbin/nologin
[root@extmail ~]# adduser sale02 -s /sbin/nologin
[root@extmail ~]# useradd saleman -s /sbin/nologin
[root@extmail ~]# useradd boss -s /sbin/nologin
[root@extmail ~]# groupadd manager
[root@extmail /]# chgrp manager /tech/
[root@extmail /]# chgrp manager /sale/
[root@extmail /]# chmod 771 tech/
[root@extmail /]# chmod 771 sale/
 
关于组这块添加如下面例子:
              Vi /etc/group
tech:x:502: tech01,tech02,techman,boss  ####表示,这些用户,在此组中#####
smb.conf里面配置如下:
[public]
path = /public
public = yes
writable = yes
browesable = yes
guest ok = yes
 
[tech]
patch = /tech
valid users = @tech,@manager,@sale
write list = @tech,boss
 
[sale]
path = /sale
valid users = @tech,@manager,@sale
write list = @sale,boss