Linux 可以使用 Samba 软件包提供 SMB 服务(例如 WfW、Win95 和 NT 风格的网络文件和打印机共享)。本节将介绍如何配置共享,以及如何从客户端计算机访问它们。
Red Hat 发行版包含了 Samba 软件包,您可以输入以下命令来检查是否已安装以及您拥有的版本
rpm -q samba |
如果未安装,您需要使用 RPM 实用程序安装它。有关如何执行此操作的详细信息,请参阅第 10.1 节。
您应该关注的最重要的 Samba 文件是
Samba 配置文件,用于设置共享和其他配置参数(见下文)
Samba 日志文件的位置
建议设置文件共享的位置。但是,您应该选择文件系统上有足够空间来容纳您将存储的文件的位置。就我个人而言,我通常设置一个挂载在 /archive/ 上的大分区,并将我的共享放在这里。
文件 ``/etc/smb.conf'' 包含有关文件和打印共享的配置信息。该文件的前几行包含全局配置指令,这些指令对所有共享都是通用的(除非在每个共享的基础上被覆盖),后跟共享部分。
Samba 安装包含一个默认的 smb.conf 文件,在许多情况下,该文件应该足以满足您的需求,并且只需要进行少量更改。
这是一个此文件的示例(我已经对其进行了大量自定义,以向您展示一些更重要和有趣的选项)
# Items common to all shares (unless over-ridden on a per-share basis) [global] # Number of minutes of inactivity before client is disconnected # to avoid consuming resources. Most clients will automatically # reconnect so this is a good idea to enable. dead time = 10 # Don't let users connect as "root", just-in-case. :-) invalid users = root # Specify the account for guest shares (shares that don't require # a password to connect to. This username must be a valid user # in the /etc/passwd file. guest account = guest # Specify where log files should be written to. The "%m" suffix # means that log files will be created in the format # log.machine-name (eg. "log.twixel") log file = /usr/local/samba/logs/log.%m # Maximum size of log file, in Kilobytes. max log size = 1000 # Password level 3 means that case is not an issue when entering # passwords. A little less secure than level 1 or 2 would be, # but seems to be a fair compromise for user convenience. password level = 3 # Specify that all shares should appear in the browse list # (override any you don't want on a per-share basis). browseable = yes # If this is enabled, you can see active connections using the # "smbstatus" command. status = yes # The level of debugging information that is recorded in the log # files. Higher values generate more information (which is # probably not very useful, most of the time). debug level = 2 # This will send any Windows-style "POPUP" messages received on # the server to the postmaster by e-mail. Not very useful, but # an interesting demonstration of what can be accomplished. message command = /bin/mail -s 'Message from %f on %m' postmaster < %s; rm %s & # This is a form of caching that, when enabled, may improve # performance when reading files. read prediction = true # A list of services that should be added automatically to the # browse-list. auto services = cdrom # The location of your "printcap" file, a text file containing # definitions for your printers. printcap name = /etc/printcap # If enabled all printers in the /etc/printcap file will be # loaded into the browse-list. load printers = yes # The print command by which data is spooled to a printer under Linux. print command = lpr -r -P%p %s # The print command by which job queue information (printer status) # can be obtained. lpq command = lpq -P%p # The print command by which unwanted print jobs can be deleted # from the queue. lprm command = lprm -P%p %j # The level at which Samba advertises itself for browse elections. # Currently set to a high value to give it an even "foot-hold" with # any swarmy NT servers on the network. :-) os level = 34 # These are user's personal shares. If the client's username matches on the # server, they can access their home directory (provided they enter the # correct password). [homes] # The comments appear in the browse list. comment = Home Directories # This matches the username of the client to that of the share. # If they do not match, no share will be displayed in the browse # list, or available to connect to. user = %S # The path to the share. For example, "smithj" would map to # "/home/smithj" path = /home/%S # If enabled, allow read/write access to the shares. writeable = yes # Just an inverted synonym for "writeable". We don't *really* need # to use both. :-) read only = no # Keep this disabled so that a password is required to access these # shares. public = no # We don't want this share (after all, it is private) to appear in # the browse-list of other users. browseable = no # This is a publicly available print share, called "hp_laser". It appears # on the browse lists and can be accessed without a password by any client. [hp_laser] # The comment that appears in the browse-list. comment = Main office printer (HP Laserjet 400) # The username that this share is accessed as (guest means all users). user = guest # All generated print files will first be created in the /tmp # directory. path = /tmp # Do not allow file creation except through print spooling. writeable = no # Set permissions accordingly -- root access to print jobs only. create mode = 0700 # If this is enabled a password is not required to access the share. public = yes # This should be enabled to indicate that this is a printer share. printable = yes # Here is a service providing access to the CD-ROM device. [cdrom] comment = Shared CD-ROM drive on Linux user = guest path = /cdrom writeable = no read only = true browseable = yes public = yes guest ok = yes |
提示: 提示:从 2.0 版本开始,最新版本的 Samba 提供了一个非常简洁的基于 Web 的配置实用程序,称为 ``swat'',这使得该过程更加用户友好。该实用程序侦听服务器的 TCP 端口 901,因此要使用该实用程序,只需将您喜欢的 Web 浏览器指向如下位置
mydomain.name:901 |
(当然,为了使用 SWAT 实用程序,您需要运行 Web 服务器,例如 Apache。有关详细信息,请参阅第 7.1 节。)
与 2.0 之前的版本相比,最新的 Samba 版本也增加了相当多的功能。值得花时间升级此软件包。
客户端必须运行 TCP/IP 网络堆栈才能连接到共享。此外,为了使浏览工作正常,TCP/IP 协议必须绑定到 NETBEUI。在 Windows 95 下,可以从控制面板中的 “网络” 图标进行配置。
假设客户端已正确配置,您应该在其 “网上邻居”(如果您不使用 Windows 95/NT,则为等效的浏览方案)中看到服务器共享。然后,您可以从网上邻居映射网络驱动器,或键入共享的绝对路径(例如,“\\mail\cdrom”)。如果共享服务需要输入密码,系统将提示您输入密码。
有关 Samba 的更多信息,请访问 Samba 主页:http://samba.anu.edu.au/samba/。