SMB(Samba简称)是一组通信协议,它运行于Unix.OS/2和MS-Windows系统之间,以实现文件共享和打印机共享服务,WIDOWS客户机通过NetBIOS对话传送服务器消息来使用服务器的文件和打印机资源.NETBIOS定义了运行于DOS上的网络界面,但没有规定实际用来传送数据的网络协议.Samba使用NetBIOS over TCP/IP,这种方式有很多优点.
       SMB使LINUX计算机在网络邻居中看起来如同一台WINDOWS计算机.WINDOWS计算机的用户可以登录到LINUX计算机中,从LINUX文件系统中复制文件等.
一、启动Samba 
可以图形化启动,也可以命令行启动方式。
先检查下安装没,这里可以看到安装好了。
然后命令方式启动,成功。
二、smb.conf文件说明
下面看文件的说明
[global]                                           //设置整体环境
   workgroup = MYGROUP  //设置工作组名称,该名称会出现在WINDOWS的网上邻居和LINUX的网络服务器中。
   server string = Samba Server   // 服务器名说明
;   hosts allow = 192.168.1. 192.168.2. 127.   此选项对于安全性非常重要,它严格限制了可访问Samba Server的IP范围,默认是允许所有的IP访问,如果设置,那么设置好这后应去掉前面的“;”号
   printcap name = /etc/printcap   // 设置打印机配置文件路径
   load printers = yes           //是否将打印机共享
;   printing = cups  //打印机的类型,若使用的打印机是LINUX标准型的,则不需要更改打印机类型,通常标准型的打印机类型包括:bsd,sysv,plp,lprng,aix,hpux,qnx和cups
cups options = raw  //
;  guest account = pcguest //如果想让用户“pcguest:以匿名用户身份登录,去掉前面的“;”号,并确保在/etc/passwd中有此用户,这里的“pcguest“可以根据需要改成用户自己设置的本地用户。
 log file = /var/log/samba/%m.log   // log会在此目录中为每个登录Samba的用户建立不同的日志文件。
   max log size = 50  //定义了文件夹的大小,默认是不对日志文件做大小限制的
  
下面是关于安全级别的设置
security = user  // 安全级别,提供了4种安全等级:share,user,server,domain
;   password server = <NT-Server-Name> //密码验证服务器,当用户从WINDOWS通过SAMBA使用LINUX时,会自动传送登录WINDOWS时的用户名与密码给SAMBA,然后SAMNBA向PASSWORD SERVER验证这两项信息是否正确,若不正确,则会出现对话框,要求用户重新输入。(WINDOWS NT和WINDOWS2000也会如上,WINDOWS98只会要求输入密码,因此建议与LINUX账号相同的名称来登录WINSOW98。)而这个密码服务器可以是WINDOWS NT SERVER(通常是主域控制器),或是另外一个SAMBA SERVER。因此若SECURITY=SERVER,则需要指定密码服务器,若SECURITY=SHARE,则需删除关于密码服务器的那一行。
;  password level = 8    //密码级别设置
;  username level = 8
;  encrypt passwords = yes// 用户密码要加密,由于现在WINDOWS98/NT皆使用加密的密码,因此要有这一项,当然也可以要求使用不加密的密码。
;  smb passwd file = /etc/samba/smbpasswd  //奖密码服务器设置为SAMBA SERVER时,需要用此行来指定要验证的密码文件,若设置为WIDOWS NT SERVER,则不需要此行,这里最重要的是密码文件设置的路径。
;  unix password sync = Yes 
;  passwd program = /usr/bin/passwd %u  //接下来的两行设置用来容许WINDOWS密码改变后更新LINUX系统的密码,确定“encrypt passwords“和"smb passwd file“项被启用
;  passwd chat = *New*UNIX*password* %n\n *ReType*new*UNIX*password* %n\n *passwd:*all*authentication*tokens*updated*successfully*

;  username map = /etc/samba/smbusers//在此文件中设置对应的用户名称
;   include = /etc/samba/smb.conf.%m  //在此行允许用户自己定义每台计算机的基本配置文件,%m代表NETBIOS正在连接的计算机名称。
   socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192  //设置服务器和客户之间会话的socket选项,此项设置将优化传输速度。
;   interfaces = 192.168.12.2/24 192.168.13.2/24  //如果有多网络界面必须在此列出
;   remote browse sync = 192.168.3.25 192.168.5.255 // 本行和下一行是远程浏览设置
;   remote announce = 192.168.1.255 192.168.2.44
;   local master = no
;   os level = 33
;   domain master = yes
;   preferred master = yes 
;   domain logons = yes
;   logon script = %m.bat
;   logon script = %U.bat
;   logon path = \\%L\Profiles\%U
; name resolve order = wins lmhosts bcast
;   wins support = yes
;   wins server = w.x.y.z  //WINS客户端设置
;   wins proxy = yes障碍
   dns proxy = no   //DNS PROXY设置,默认是不为客户做DNS查询
;  preserve case = no
;  short preserve case = no
;  default case = lower
;  case sensitive = no
#============================ Share Definitions ==============================
   idmap uid = 16777216-33554431
   idmap gid = 16777216-33554431
   template shell = /bin/false
   winbind use default domain = no
[homes]   //用户访问自己目录的设置
   comment = Home Directories  //说明文件或目录类型
   browseable = no    //用户私人目录,不需要给别人浏览
   writable = yes    //用户写入自己目录的权限
# Un-comment the following and create the netlogon directory for Domain Logons
; [netlogon]  //域用户登录目录设置
;   comment = Network Logon Service
;   path = /home/netlogon
;   guest ok = yes
;   writable = no
;   share modes = no

# Un-comment the following to provide a specific roving profile share
# the default is to use the user's home directory
;[Profiles]   //默认PROFILE设置
;    path = /home/profiles
;    browseable = no
;    guest ok = yes

# NOTE: If you have a BSD-style print system there is no need to
# specifically define each individual printer
[printers]   //打印机设置
   comment = All Printers    //说明要把全部打印机共享
   path = /var/spool/samba   //打印机池,用户必须自行创建目录
   browseable = no   //此地存放打印机的临时文件
# Set public = yes to allow user 'guest account' to print
   guest ok = no
   writable = no
   printable = yes  //用户是否可以打印
# This one is useful for people to share files
;[tmp]   //用户共享资源设置(可定义新的共享目录)
;   comment = Temporary file space   //说明
;   path = /tmp  //共享目录设置
;   read only = no  //是否只读或可写入
;   public = yes   //是否共享
# A publicly accessible directory, but read only, except for people in
# the "staff" group
;[public]  //用户资源共享设置
;   comment = Public Stuff
;   path = /home/samba
;   public = yes
;   read only = yes
;   write list = @staff
# Other examples.
#
# A private printer, usable only by fred. Spool data will be placed in fred's
# home directory. Note that fred must have write access to the spool directory,
# wherever it is.
;[fredsprn]
;   comment = Fred's Printer
;   valid users = fred
;   path = /homes/fred
;   printer = freds_printer
;   public = no
;   writable = no
;   printable = yes
# A private directory, usable only by fred. Note that fred requires write
# access to the directory.
;[fredsdir]
;   comment = Fred's Service
;   path = /usr/somewhere/private
;   valid users = fred
;   public = no
;   writable = yes
;   printable = no
# a service which has a different directory for each machine that connects
# this allows you to tailor configurations to incoming machines. You could
# also use the %u option to tailor it by user name.
# The %m gets replaced with the machine name that is connecting.
;[pchome]
;  comment = PC Directories
;  path = /usr/pc/%m
;  public = no
;  writable = yes
# A publicly accessible directory, read/write to all users. Note that all files
# created in the directory by users will be owned by the default user, so
# any user with access can delete any other user's files. Obviously this
# directory must be writable by the default user. Another user could of course
# be specified, in which case all files would be owned by that user instead.
;[public]
;   path = /usr/somewhere/else/public
;   public = yes
;   only guest = yes
;   writable = yes
;   printable = no
# The following two entries demonstrate how to share a directory so that two
# users can place files there that will be owned by the specific users. In this
# setup, the directory should be writable by both users and should have the
# sticky bit set on it to prevent abuse. Obviously this could be extended to
# as many users as required.
;[myshare]
;   comment = Mary's and Fred's stuff
;   path = /usr/somewhere/shared
;   valid users = mary fred
;   public = no
;   writable = yes
;   printable = no
;   create mask = 0765
 
三.配置Samba服务器
1.配置share级服务器.
share级在4个等级中是最低的,配置方法也是最简单.只需修改/etc/smb.conf文件如下:
看最后一行,允许IP段访问.
看光标所在处,这里需要指定一个用户账号,yang是服务器中已经存在的一个账号.
光标处是share
[tmp]这里是可以设置要共享的任何目录.
设置好后要检查正确性了.
执行testparm命令.测试smb.conf的正确性
有"OK"表示加载正常.
下面按ENTER
上面列出了配置的情况
执行snvclient命令查看资源共享情况.
最后要重新启动Samba服务.使配置文件生效.
下面来看测试.
这是在WINDOWS上,打开网上邻居.可看到配置时显示的名称LINUX.
进去以后看到服务器.
可看到配置的共享文件夹TMP
进去后可访问里面的内容了.可知配置成功.
然后来看用LINUX客户访问
在LINUX系统中,打开应用程序/网络服务器.然后点WINDOWS网络.
可看到LINUX
可看到刚才第一个画面的HAIDA,其实是一样的.
可看到共享文件夹是一个卷.
进去后同样可访问其内容了.
 
 
本文出自 “yangming.com” 博客,请务必保留此出处[url]http://ming228.blog.51cto.com/421298/109993[/url]