FreeBSD连载(67):配置samba
配置samba
虽然缺省情况已经适合大部分用户访问自己在服务器上的个人目录的要求,但是为了充分发挥samba提供的功能,与这些复杂多样的Windows网络相适应,就必须更改smb.conf的设置。以提供更多的共享设置、服务器设置,以及用于支持包括比较简单的共享方式和复杂的域认证方式在内的认证方式。
smb.conf中的语法非常简单,整个配置文件分为多个不同的部分,每个部分具有一个标题。使用方括号将标题引起来,标题下包括一些相关设置,每一行都用于一个相关设置。设置文件中的每个部分或者定义了一个共享资源的名字,或者设置了一组参数。以下以缺省smb.conf为例,介绍smb.conf中的相关设置。
- [global]设置
# This is the main Samba configuration file. You should read the # smb.conf(5) manual page in order to understand the options listed # here. Samba has a huge number of configurable options (perhaps too # many!) most of which are not shown in this example # # Any line which starts with a ; (semi-colon) or a # (hash) # is a comment and is ignored. In this example we will use a # # for commentry and a ; for parts of the config file that you # may wish to enable # # NOTE: Whenever you modify this file you should run the command "testparm" # to check that you have not many any basic syntactic errors. # #======================= Global Settings ===================================== [global] |
[global]部分定义了服务器本身使用的配置参数,以及其他共享资源部分使用的缺省配置参数,因此相当重要。
# workgroup = NT-Domain-Name or Workgroup-Name, eg: REDHAT4 workgroup = MYGROUP |
工作组设置本地网络使用工作组名字(或者是NT域名字),这对于将正确进行浏览数据中非常重要。否则,Windows客户就不能从其网络邻居中发现这个Samba服务器。
# server string is the equivalent of the NT Description field server string = Samba Server |
server string是对于本地服务器的简单描述,这些信息将作为这台服务器的属性,返回给Browser,显示在Windows客户中作为对这个服务器的描述。
# This option is important for security. It allows you to restrict # connections to machines which are on your local network. The # following example restricts access to two C class networks and # the "loopback" interface. For more examples of the syntax see # the smb.conf man page ; hosts allow = 192.168.1. 192.168.2. 127. |
hosts allow参数用于限制可以访问这台samba服务器的客户机的IP地址范围,通过指定一系列网络地址,使得只有这些网络中的计算机才能访问这台服务器提供的资源,以提供安全限制。缺省情况下,这行配置被注释了,使得所有的客户都可以访问这台计算机,这样就存在一定的安全问题。
# If you want to automatically load your printer list rather # than setting them up individually then you'll need this load printers = yes # you may wish to override the location of the printcap file ; printcap name = /etc/printcap # on SystemV system setting printcap name to lpstat should allow # you to automatically obtain a printer list from the SystemV spool # system ; printcap name = lpstat # It should not be necessary to specify the print system type unless # it is non-standard. Currently supported print systems include: # bsd, sysv, plp, lprng, aix, hpux, qnx ; printing = bsd |
这些设置是用于设置samba服务器的打印机资源,load printer=yes就允许samba服务器对外共享服务器的打印机。由于不同的Unix系统中会使用不同的打印系统和不同的打印设置文件,因此需要设置正确的 printcap和printing类型,对于使用BSD打印系统的FreeBSD来讲,打印系统为BSD,使用的设置文件为 printcap,这些是缺省设置,不需要改动。对于使用Unix System V打印系统的Samba,则需要重新进行设置。
# Uncomment this if you want a guest account, you must add this to /etc/passwd # otherwise the user "nobody" is used ; guest account = pcguest |
由于Mircrosoft客户没有用户的概念,因此有时会用没有用户和口令的请求访问服务器,就需要将这个没有用户的请求映射为系统中的某个用户,Samba服务器才能安全的访问系统。guest account 就定义这样的请求在Unix下对应的用户权限。为了安全的原因,不能让这个帐户在系统中有可写的权限,通常可以增加一个专用帐户,如pcguest。如果这个设置被注释的情况下,系统缺省使用nobody执行 Windows客户的请求。一些使用者建议不要使用nobody用户,因为系统中的很多程序缺省都使用它,因此就会有安全问题。
# this tells Samba to use a separate log file for each machine # that connects log file = /var/log/log.%m # Put a capping on the size of the log files (in Kb). max log size = 50 |
这里定义samba的日志文件为/var/log目录下的以log为前缀的文件,%m用于代表从访问的NetBIOS 计算机名,如果使用的用户级认证,还可以使用%U表示不同的登录用户。例如从一台名字为win95c的计算机访问samba服务器的日志,将记录在/var/log/log.win95c文件中。max log size定义每个日志文件的存储限制。
# Security mode. Most people will want user level security. See # security_level.txt for details. security = user # Use password server option only with security = server ; password server = <NT-Server-Name> # You may wish to use password encryption. Please read # ENCRYPTION.txt, Win95.txt and WinNT.txt in the Samba documentation. # Do not enable this option unless you have read those documents ; encrypt passwords = yes |

