samba 使用

    技术2024-06-10  68

    桑巴简介

    教程路线图

    尽管您无需成为Samba专家即可完成本教程,但对常见管理任务的基本知识会有所帮助,包括复制和移动文件,创建用户帐户以及设置权限等任务。

    完成本教程后,您将知道如何:

    使用Redhat软件包管理器(RPM)或从源代码编译程序来安装Samba。 将Samba服务器配置为PDC(主域控制器)。 配置服务器以支持漫游配置文件。 配置服务器以支持netlogons。 在服务器上创建所需的管理目录,并根据需要设置其权限。 在域控制器上创建用户和计算机(信任)帐户。 配置客户端计算机以加入域。 并排除在上述过程中可能出现的任何基本问题。

    什么是桑巴舞

    Samba可以说是有史以来最成功的开源项目之一。 它像许多其他类似项目一样开始:作为需要。 Andrew Tridgell的本地网络需要一个文件服务器程序,该程序支持Digital Pathworks的旧DEC协议。 安德鲁不为人知,该协议后来成为SMB(Microsoft文件系统的语言)。 自成立以来的11年间,Samba已经发展成为一种稳定,可靠的产品,并已移植到众多平台(AIX,HP-UX,BSD,Linux,DigitalUnix,IRIX,SCO,VMS,OSF和Solaris)。 安装和配置后,Samba可以与现有Windows网络进行几乎无缝的集成,并且从用户的角度来看,从所有意图和目的出发,它仅仅是另一台Windows文件服务器,打印机服务器或域控制器。 最重要的是,Samba是免费的,没有传统许可问题可以解决。 关于PDC功能(本教程的主题),Samba当前支持:

    从Windows NT / 2000客户端进行域登录。 Windows 9x / ME客户端的用户级安全性(Win9x / ME客户端没有域级安全性的概念;他们只知道如何登录到域控制器)。 漫游配置文件。 NT4样式的系统策略。 浏览列表。 检索存储在Samba PDC上的用户和组列表。

    撰写本文时,Samba的当前稳定版本是2.2.3a版,它将用作本教程的基础。 请注意,当前的SAMBA_2_2 CVS开发树即将发布(计划于2002年4月中旬发布),该树将成为2.2.4。 检查Samba的网站( www.samba.org )以获得发行说明和详细信息; 如果Samba 2.2.4可用,请使用它-它包括与打印和域控制器功能有关的多个重要错误修复。

    目前的计划限制

    尽管Samba中的功能可以与Windows NT / 2000服务器相比,但是Samba确实有一些限制,您应该意识到:

    Samba不能充当BDC(备份域控制器)的角色。 当前尚无法在Samba域控制器和Windows NT / 2000控制器之间建立“信任”关系。 话虽如此,Scott Merrill设计了一种使用两台Samba机器模拟PDC / BDC环境的方法。 有关详细信息和URL,请参见参考资料部分 。 同样,Samba无法使用Windows NT / 2000服务器复制SAM(用户身份验证信息)(反之亦然)。 Samba尚未读取或使用Windows Active Directory(AD)。 Samba不支持通过Windows域用户管理器添加用户(主要是由于上述限制)。

    请继续关注。 上述许多限制(主要是与AD树和SAM复制进行对话的能力)将随Samba 3.0消失,Samba 3.0目前正在积极开发中(计划于2002年夏末发布)。 除了与Windows AD的连接性之外,Samba 3.0还(可能)具有以下功能:Microsoft Kerberos身份验证,完全重写和可配置的身份验证子系统,类似于Microsoft的用于终端访问各种网络资源的“ NET”命令,已得到改进打印支持,以及常见的错误修复和稳定性增强。

    有关Samba 3.0和其他开发项目的状态的更多详细信息,请访问www.samba.org/samba/ 。

    硬件注意事项

    总体而言,Samba是一个非常高效的程序,并且仅花费很少的系统资源即可完成工作。 但是,就像任何一线软件程序一样,它实际上是按比例缩小的-您不能期望200个Samba用户从具有64MB RAM和10GB IDE硬盘的Pentium 166上运行,而不会造成复杂性(以及许多沮丧的用户) 。 另一方面,考虑到文件传输负载很轻,充当小型家庭办公室的Samba文件服务器的同一台Pentium 166可能会做得令人钦佩。

    通常,从硬件角度来看,我建议以下内容:

    大量的内存-越多越好。 每个用户连接都会产生一个Samba守护程序,因此您计划托管一台计算机的用户越多,它应该拥有的内存就越多。 磁盘访问至关重要。 通过简单地添加SCSI子系统和高质量的SCSI硬盘驱动器,我已经从旧的工作站(PII-400)构建了完全合适的Samba文件服务器。 再次考虑规模问题–您计划服务的用户越多,磁盘子系统的质量就应该越高。 我个人更喜欢SMP文件服务器。 多个处理器不一定会使机器更快,但确实会使机器在负载下不会变慢。 考虑到您可以以与高端单P4处理器系统相同的成本构建双Celeron系统的事实,对我而言,选择无疑是明智的。

    作为记录,用于编写和测试本教程的硬件包括一台IBM新的xSeries服务器:xSeries 220型,双奔腾3 1.2GHz CPU,IBM ServeRAID硬件RAID控制器,1GB SDRAM和三个10,000 RPM 18GB RAID5配置中的硬盘驱动器(可使用约36GB的可用硬盘空间)。 该机器在所有方面均表现出色,并继续做到这一点而没有错误或失败。

    有关IBM服务器产品线的更多详细信息,请参阅eServer开发人员域或有关xSeries的特定信息,请参见基于xSeries Intel处理器的服务器站点。 还有一本出色的IBM红皮书,标题为《 Samba安装,配置和大小调整指南》 (SG24-6004-00),其中很好地介绍了硬件要求和大小调整。

    教程先决条件

    安装Samba并将其配置为PDC要求必须遵循某些步骤。 尽管读者不一定非要成为Samba专家即可受益于本教程,但对常见管理任务(如复制和移动文件,创建用户帐户和设置权限)的基本知识将有所帮助。

    如果要按照示例操作,则需要以下配置和工具:

    本教程基于Redhat 7.2,并应用了所有当前勘误(有关详细信息,请参见Redhat的勘误页面)。 当然,您可以使用您选择的任何UNIX或Linux发行版(哎呀,您甚至可以使用HP-UX或Solaris!)—只要注意所指出的文件位置和路径是Redhat特定的即可。 但是,在尝试安装和配置Samba之前,请确保您选择的任何发行版都可以正常运行。 像vi这样的文本编辑器的工作知识是拥有和/或开发的一项很好的技能。 讨论了一个基于浏览器的配置工具(SWAT),有关此工具的信息可以在“ 疑难解答和SWAT信息”部分中找到。 如果您计划从源代码编译Samba(这是推荐并演示的方法),请确保已在计算机上安装并正确配置了gcc。

    构建和配置Samba PDC

    服务器端配置

    本节介绍使用Samba构建和配置PDC的服务器端详细信息。 在构建和配置PDC时,务必注意细节。 当项目无法按公告工作时,十分之九是人为错误:缺少编译时选项,配置文件中的拼写错误,权限位设置不正确等。此处的消息应有条不紊。

    要使Samba PDC联机,需要执行以下一般步骤:

    构建/安装Samba(如果尚未安装) 配置smb.conf文件 在服务器上创建所需的目录(如果要使用登录脚本或漫游配置文件) 创建用户和机器帐户 测试配置并启动守护程序

    最后一步是配置各个客户端并将它们加入域。 下一节“ 客户端配置”中将对此进行讨论。

    安装Samba

    第一步是确保在系统上安装了Samba。 如果不是,则需要安装它。 检查此问题的最简单方法(再次,在本教程中我们假设Redhat 7.2)是键入:

    rpm -qa | grep samba

    它将生成已安装的与Samba相关的RPM软件包的列表,或生成空白行。

    如果安装了Samba,请记下版本号。 在构建Samba域控制器时,经验建议至少使用2.2.2版本。 更好的是,使用最新的稳定代码,撰写本文时为2.2.3a。 在最近的两个或三个修订中,有关域控制器功能的许多工作已经完成。 此外,打印功能已得到认真的重新设计,LDAP后端现在已经足够稳定,可以被认为具有“生产”能力,并且已经消除了许多小错误。 总而言之,版本2.2.3a是稳定,完善和经过测试的版本。

    如果计划安装或升级,则有两种解决方法:从源代码进行编译,或安装预构建的RPM软件包。 我们将在下一个面板中查看“从源编译”选项。

    通过RPM安装时,需要牢记一些注意事项。

    首先,Redhat将其二进制Samba RPM分为三个部分: samba-common-xxxxx.rpm ; samba-server-xxxxx.rpm ; 和samba-manual-xxxxx.rpm ,其中x表示发行版本。 Samba团队还为各种平台构建二进制软件包(请参阅http://us1.samba.org/ftp/Binary_Packages ),但是他选择为Redhat发行版创建单个安装RPM。 因此,为确保一切都正确升级,请在安装新版本之前卸载所有现有的Samba软件包! ( rpm -e samba )。

    其次,如果您要保留现有的配置文件,请将其备份到安全的地方。 可能由于安装出错而丢失了有价值的配置文件。

    输入man rpm,以解释可用于安装RPM的各种选项。 rpm -ivh samba-package命令应该可以满足大多数需求。

    从源头建造

    许多管理员喜欢从源代码构建所有关键服务器程序(例如,Apache,BIND,Samba等)。 原因很简单:从源代码构建意味着您可以根据需要定制程序的功能和组件。 您还可以根据“干净,原始”的源代码确切地了解系统上的功能。 但是,由于目录/文件位置的差异,在Redhat发行版上构建Samba可能会有些棘手。 RH的人员将/ usr指定为基本安装目录。 这意味着用户可访问的实用程序位于/ usr / bin中,而管理员实用程序位于/ usr / sbin中。 配置文件位于/etc/samba 。 另一方面,缺省的Samba配置(意味着从没有配置选项的源构建)使用/usr/local/samba作为基础。 因此,二进制文件安装在/usr/local/samba/bin ,安全二进制文件存储在/usr/local/samba/sbin ,并且,很直观地,Samba的配置文件最终存储在/usr/local/samba/lib 。

    当不熟悉上述约定的人从源代码安装Samba而不卸载Redhat版本时,就会出现“陷阱”。 他最终在系统上使用了两个不同的版本,并且无法弄清楚为什么-在安装了闪亮的新Samba版本后-他的旧版本仍在运行。 之所以调用旧版本,是因为:

    旧版本位于“路径”上; 新版本不是。 旧版本(已构建RH)由/etc/init.d的脚本samba自动启动(在某些安装中,该文件可能称为smb)。 从源进行安装并不总是会在脚本中创建或纠正路径。

    提示:您可以通过键入/usr/local/samba/bin/smbd -V (或Samba二进制文件所在的路径)来确定Samba的版本。

    因此,从源头构建时,必须做出的第一个决定是:Samba将驻留在哪里?

    在/usr/local tree安装Samba并没有错; 您只需要记住它的存在,并记得在运行程序的某个实用程序时键入完整路径(或将文件位置添加到该路径)。 后者确实不是什么大问题,因为一旦配置,启动并运行了Samba,它就会继续前进,然后不断前进……

    另一方面,如果您的策略是将所有程序文件都保留在bin / sbin目录中,那也是可行的。 下一个面板包含用于从源代码构建Samba的分步清单,以及用于执行此操作的示例./configure命令。

    从源代码构建:清单

    以下清单应使任何不熟悉从源代码开始构建和运行的人员都可以大惊小怪和无所事事:

    如果您已经安装了Samba(换句话说,是从RH RPM软件包中安装的),请转至/etc/init.d并将文件samba(或smb)复制到一个安全的地方,以备将来参考。 另外,如本教程前面所述,以防万一,请复制现有smb.conf 。 删除所有现有的Samba安装。 从您喜欢的Samba网站下载源tarball。 最新的稳定版本始终称为samba-latest.tar.gz 。 请参阅“ 相关主题”部分,以获取必需的URL。 我更喜欢将所有源代码构建在/usr/local/src ,因此该位置仅供参考-根据需要替换。 将tar.gz文件复制到/usr/local/src (或者更好的是,直接在此处下载tarball),然后键入tar xvzf samba-latest.tar.gz 。 CD到源目录( /usr/local/src/samba/source )。 请注意,许多应用程序都从解压缩后的根目录( /usr/local/src/samba )配置为./configure 。 Samba并非如此,这是不熟悉该程序的人经常犯的错误。 如果您愿意在/usr/local/samba下安装/usr/local/samba ,则--prefix= and xxxdir= options 。 键入./configure --help查看Samba的配置选项。 以下是Redhat配置选项的配方。 显示的目录放置选项会将Samba放置在与Redhat构建的RPM相同的位置。 完成无错配置后,输入make 。 要将二进制文件复制到他的最终安息地,请输入make install 。 请注意:如果必须使用其他选项返回并重新配置Samba,请确保在重新运行./configure命令之前删除/usr/local/src/samba/source/config.cache文件。 否则,Samba将使用先前的选项集进行自我配置。

    而已! 现在,您应该已经可以正常安装Samba。 现在将其配置为执行某些操作...

    清单1. Samba安装
    ./configure \ --prefix=/usr \ --bindir=/usr/bin \ --sbindir=/usr/sbin \ --libexecdir=/usr/libexec \ --datadir=/usr/share/samba \ --sysconfdir=/etc/samba \ --localstatedir=/usr/local/samba/var \ *** CHECK THE ABOVE *** --libdir=/usr/lib \ --with-lockdir=/var/locks/samba \ --with-swatdir=/usr/share/samba/swat \ --with-codepagedir=/etc/samba/codepages \ --with-configdir=/etc/samba \ --with-smbwrapper \ --with-automount \ --with-smbmount \ --with-pam \ --with-pam_smbpass \ --with-winbind

    smb.conf简介

    Samba的强大功能和灵活性由单个配置文件smb.conf 。 如本节前面所述, smb.conf's位置取决于构建程序时使用的程序位置选项。 smb.conf的两个典型位置是/usr/local/samba/lib和/etc/samba 。 Samba的新手应该做的第一件事是:(a)复制smb.conf以便始终拥有“干净的”原始文件; (b)打印出来并阅读! smb.conf有大量文档记录,是对新手和经验丰富的退伍军人都有宝贵信息的金矿。

    smb.conf的结构和布局非常简单。 它由两个主要部分组成:[global]包含“全局”应用于程序的选项语句,以及“ shares”部分。 每个共享均以方括号括起来的共享名称(例如[homes])开头,并列出适用于该共享的期权声明列表。 这是重要的注释,可供将来参考:每个Samba选项语句都有一个默认值。 因此,在global部分中指定其他值将覆盖整个服务器的默认值,而在shares部分中指定值将覆盖全局选项和服务器的默认选项(如果不同)。

    有一个简单的例子。 默认情况下(例如,全局默认选项),Samba允许通过身份验证过程的任何人(通常是有效的用户名/密码组合)访问列出的共享。 但是,管理员可以使用有效用户=选项来限制用户对共享的访问。 例如:

    清单2.一个例子
    [homes] comment = Home Directories valid users = tom, leah, suzie, bilbrey read only = No browseable = No

    只有用户tom,leah,suzie和bilbrey可以访问上述共享,从而有效地覆盖了配置文件的[global]部分中指定的任何其他选项(暗示或其他方式)。

    足够的理论。 让我们继续学习有趣的东西-配置Samba域控制器。

    基本服务器设置

    太多的管理员创建了六页或七页的初始配置文件,并且发现如果配置无法提供预期的结果,他们就会抽出大量的头发。 所有这些导致不必要的复杂的六页或七页。 如您所见,提供域身份验证,登录脚本选项,漫游配置文件和一些基本共享的“基本”配置实际上非常容易构建。 因此,本着保持简单的精神,我们将smb.conf文件放在一起,分成一些小的块。 这使您可以查看哪些选项可以做什么,并以可咀嚼的块的形式消化该过程。 可以从“ 相关主题”部分下载完整的,功能齐全的smb.conf 。

    与其乱删除和编辑随Samba安装的六页或七页配置文件,不如从空白开始并添加以下域/机器选项:

    清单3.域/机器选项
    # /etc/samba/smb.conf # samba configuration file # last updated: 2/28/2002 by tms [global] ;basic server settings workgroup = syroidmanor netbios name = phoenix server string = Samba PDC running %v socket options = TCP_NODELAY IPTOS_LOWDELAY SO_SNDBUF=8192 SO_RCVBUF=8192

    注释以井号( # )或分号( ; )开头,将被忽略; 空格也是如此。 对于那些还没有这样做的人,在配置文件中提供自由注释是一个很好的习惯(特别是在您进行配置更改时;请注意更改以及更改原因)。 对于域控制器,工作组选项用于设置控制器将服务的域名。 是的,我本可以使用syroidmanor.com ,但是syroidmanor可以工作,并且用户和管理员的键入都更少。 netbios选项是主机名。 因此,此系统的FQDN(完全合格域名)为phoenix.syroidmanor[.com] 。 当从Windows客户端浏览“网上邻居”时, server string提供的描述显示在共享旁边。 接下来,我们需要告诉Samba这台机器是PDC。 最后, socket options设置控制TCP / IP性能。 已知显示的设置适用于基于Linux的系统。 如果您使用的是其他操作系统,请查阅本教程末尾列出的文档参考之一。

    PDC和主浏览器设置

    首先,请注意:网络上只能有一个PDC。 在网络上拥有多个PDC不会使您头疼和无法解释的怪异现象永无止境-不要去那里。

    在现有的smb.conf文件中,将以下选项添加到global部分:

    清单4. smb.conf文件- Global部分
    [global] ... ;PDC and master browser settings os level = 64 preferred master = yes local master = yes domain master = yes ...

    引用O'Reilly&Associates的开创性标题“ 使用Samba” (Eckstein,Collier-Brown和Kelly; 有关更多详细信息,请参阅“ 相关主题”部分):...每个子网中的一台计算机始终保留当前活动计算机的列表。 该列表称为浏览列表,维护该列表的服务器称为本地主浏览器 。 随着计算机上下网络,本地主浏览器会不断更新浏览列表中的信息,并将其提供给请求该信息的任何计算机。”鉴于本地主浏览器本身可能不可用, 将按常规调用选举以确定谁的权限是绝对的(即哪台机器拥有最准确的本地主浏览列表)选举的获胜者取决于许多因素:选举协议(此时无意义),操作系统级别,首选主机设置,在线时间,最后根据机器的NetBIOS名称按字母顺序排列。上述配置中的前三个设置确保始终就当前浏览列表始终咨询该机器。 domain master选项是“ switch”,它指示Samba将成为主域控制器。

    安全设定

    下一步是添加一些安全性和日志记录选项:

    清单5.安全和日志记录选项
    [global] ... ;security and logging settings security = user encrypt passwords = yes domain logons = yes log file = /var/log/samba/log.%m log level = 2 max log size = 50 hosts allow = 127.0.0.1 192.168.1.0/255.255.255.0

    ...

    Samba支持四个安全选项:共享,用户,服务器和域。 必须在Samba PDC上将安全选项设置为user。 有关其他安全模式的说明,请参阅先前参考的“ 使用Samba”标题中的第164页。 对于PDC,“ encrypt passwords = yes选项也是必需的。 我们将在本教程的“ 客户端配置”部分中简要介绍此设置的含义。 domain logons选项只是告诉Samba支持此计算机上的域登录(与通过PDC进行身份验证然后将客户端发送到另一台计算机以获取登录脚本,主目录等相反)。 下一个选项确定日志文件的存放位置; %m是替代变量 。 它被连接机器的netbios名称替换(请参阅使用Samba 。可接受的变量范围是1到10。除非需要非常详细的调试信息,否则建议不要运行高于3的日志级别;高日志记录选项会大大降低系统速度为了产生可控制的日志文件(填充/ var分区会带来非常“不好的后果”),我们将max log size = 50设置max log size = 50 ,这会将每个日志文件的最大max log size = 50限制为50 KB;达到此大小后,新条目将替换最旧的条目。最后但并非最不重要的一点是,我们确保只有内部192.168.1子网中的计算机才能连接到服务器。不要忘记添加localhost条目,特别是如果您打算使用扑打。

    漫游配置文件

    接下来,我们将添加对漫游配置文件的支持。 本地配置文件由存储在用户计算机上C:/Documents and Settings/username下的所有文件和设置(桌面,未存储在注册表中的应用程序配置文件,Internet缓存文件等,等等)组成。 启用漫游配置文件(或仅配置文件)后,这些设置将存储在本地计算机上的其他文件夹中(例如C:/Documents and Settings/tom.SYROIDMANOR ),并在注销时存储到PDC的目录中。 当用户重新登录时,服务器设置将还原到本地主机。 所有这些奇特的目的是允许用户从网络上的任何计算机登录到域,并使他们保存的“桌面”设置,“开始”菜单和各种配置设置看起来像魔术一样。 配置文件有一个警告:配置文件同步可能消耗大量带宽。 如果您的网络已经很薄,则漫游配置文件绝对不是一个好主意。 首先,让我们填充配置文件,然后解释各种选项的作用。

    清单6.配置文件
    [global] ... ;user profiles and home directory logon home = \\%L\%U\.profile logon drive = H: logon path = \\%L\profiles\%U ... #===Shares=== [homes] comment = Home Directories browseable = no writeable = yes [profiles] path = /home/samba/profiles writeable = yes browseable = no create mask = 0600 directory mask = 0700

    上面的全局选项块要注意的最重要一点是,所引用的目录必须带有匹配的共享(在这种情况下为配置文件)。 并确保您拼写的全局引用和共享名称相同。 一个常见的错误是拼写一个“配置文件”和一个“配置文件”。 发生这种情况时,将拒绝用户访问PDC。 此外,目录必须存在并且必须在目录上设置适当的权限。 目录创建和权限将在本节后面详细介绍。

    如您所见,登录路径=选项使用变量替换并与[profiles]共享配对。 假设我的用户名是tom,并且我尝试连接到名为phoenix的PDC,则登录路径行将替换为\\ phoenix \ profiles \ tom(%L = Samba服务器的netbios名称= phoenix;%U =用户名要求分享= tom)。 程序中的配置文件名称引用了[profiles]共享。 综上所述,我们提出以下内容:“当用户tom尝试登录phoenix时,可以在/home/samba/profiles/tom目录中找到其个人资料(对于首次登录,Samba将创建该个人资料。为了安全起见,为了使我们安全,我们使[profiles]共享不可浏览(隐藏在浏览“网上邻居”的任何人中),可写(如果要更新/保持用户的个人资料是必需的),我们将创建掩码设置为0600( rwx-xxx-xxx-只有用户可以在那里读取/写入文件,并且我们强制将创建的任何目录设置为0700(rwx-xxx-xxx-如果要导航他,则目录必须是可执行的)。

    需要注意的另一件事:Windows NT / 2000客户端实现配置文件的方式与Windows 9x / ME客户端不同,因此,“登录”路径的两种不同方法。 登录主目录特定于Win9x / ME; Win9x / ME将配置文件限制为用户的主目录。 登录路径是Windows NT / 2000专用的,没有这种限制。 在配置文件中同时具有这两个选项只会扩展其适用性。 当然,如果站点上没有Win9x客户端,请随时删除。

    接下来,我们将研究特殊的[homes]共享及其工作方式。

    [房屋]份额

    [homes] (注意!这是“ homes”,而不是“ home”)共享是Samba配置文件中三个特殊部分之一(其他两个是[global]和[printers] )。 如果客户端尝试连接到不存在的共享,并且smb.conf中存在[homes]共享,则Samba会假定用户正在尝试连接到其主目录。 然后,该程序在其用户数据库(smbpasswd;有关此主题的更多信息,请继续关注)中搜索与请求无效共享的用户相同的用户名和密码组合。 如果找到,则将用户名替换为登录主目录选项语句。 以我们的朋友汤姆为例,全局选项将扩展为\\%L\%U ,而后者又转换为\\phoenix\tom 。 如果不存在名为[tom]共享,Samba将使用[homes]共享中提供的path =选项创建一个共享,并为该共享分配Windows驱动器盘符...是的,您猜中了... H:(根据全局选项登录驱动器= H :;这可以是客户机上尚未使用的任何驱动器号)。 如果[homes]下不存在path =语句,则假定为/ home / username。 很聪明的程序,您不是要说吗?

    我们还有另外一个要考虑的全球/股票期权配对:netlogon。

    netlogon选项

    我们要添加到smb.conf的最后一部分(好吧,至少现在是...)是登录脚本选项。 像[房屋]和[个人资料]份额一样,这个难题有两部分:

    清单7. Netlogon选项
    [global] ... logon script = netlogon.bat ... # === shares === ... [netlogon] path = /home/netlogon read only = yes write list = tom

    [netlogon]共享是一种管理工具,主要用于通过注册表修补程序,防病毒更新,程序更新等项目来全局更新客户端计算机。任何要“推送”到客户端的操作都可以通过netlogon完成。 此外,您可以使用共享在一个或多个客户端上实施系统策略,或者在用户每次登录时备份选定的文件组。 创建从netlogon运行的脚本超出了本教程的范围,但是您可以在Samba.org网站上以及通过使用字符串“ samba scripting”搜索Google来找到大量信息。

    netlogon的工作方式如下:每当存在用户登录到PDC以及logon script = option和[netlogon]共享时,Samba就会转到指示的路径并执行登录脚本引用的文件。 再次提醒您一些简短的警告:

    只要Windows将其识别为可执行文件,登录脚本引用的文件都可以称为任何文件。 如果找不到引用的文件,则Samba会继续进行,并将用户连接到请求的共享。 确保将UNIX端权限设置为可执行。 要委派netlogon共享中脚本的职责,请创建一个“ admin”组,然后将该组添加到以下形式的write list = option中: write list = @admin (“ @”表示一个组)。 确保在非生产环境中彻底测试脚本。 在600台客户端计算机上破坏注册表不是一个好职业。

    最终剪辑

    以下是供参考的完整Samba PDC配置文件:

    清单8. Samba PDC配置文件
    # /etc/samba/smb.conf # samba configuration file # last updated: 2/28/2002 by tms [global] ;basic server settings workgroup = syroidmanor netbios name = phoenix server string = Samba PDC running %v socket options = TCP_NODELAY IPTOS_LOWDELAY SO_SNDBUF=8192 SO_RCVBUF=8192 ;PDC and master browser settings os level = 64 preferred master = yes local master = yes domain master = yes ;security and logging settings security = user encrypt passwords = yes log file = /var/log/samba/log.%m log level = 2 max log size = 50 hosts allow = 127.0.0.1 192.168.1.0/255.255.255.0 ;user profiles and home directory logon home = \\%L\%U\ logon drive = H: logon path = \\%L\profiles\%U logon script = netlogon.bat # ==== shares ==== [homes] comment = Home Directories browseable = no writeable = yes [profiles] path = /home/samba/profiles writeable = yes browseable = no create mask = 0600 directory mask = 0700 [netlogon] comment = Network Logon Service path = /home/netlogon read only = yes browseable = no write list = tom

    接下来是身份验证主题:将用户帐户和计算机帐户添加到域控制器。

    目录,帐户和身份验证

    创建PDC管理目录

    现在我们已经有了一个PDC配置文件,是时候完成其余的服务器端管理项目了。 也就是说,在smb.conf创建共享所需的必要目录,对这些目录设置适当的权限,并添加必要的用户/机器帐户。

    但是首先,让我们创建两个组来帮助管理域:

    [root@phoenix root]# group -g 200 admins [root@phoenix root]# group -g 201 machines

    第一条命令创建GID为200的管理组(选择该组以不与任何其他现有组冲突); 第二个组创建一个GID为201的计算机组。第一个组将包含被允许管理PDC某些方面的用户。 第二组是组织即将创建的机器帐户的便捷方法。

    现在上述组已经就位,我们可以继续创建两个必需的目录并设置正确的所有权。

    [root@phoenix root]# mkdir -m 0775 /home/netlogon [root@phoenix root]# chown root.admins /home/netlogon [root@phoenix root]# mkdir /home/samba /home/samba/profiles [root@phoenix root]# chmod 1757 /home/samba/profiles

    在上述目录上设置正确的权限和所有权是保护服务器安全的关键步骤。 不要忘了,当客户端登录到服务器,在任何文件中/home/netlogon命名的目录(在我们的示例配置) netlogon.bat将自动下载并执行。 无需脑外科医生就能看到在网络上的每个客户端上编写破坏性脚本或植入特洛伊木马都是多么容易。 在/home/samba/profiles上设置的“ chown”命令对用户安全同样重要。 实际上,此命令设置目录权限,以使root拥有所有内容,直到树的“ profiles”分支,而用户拥有该目录下的所有内容(为保存其个人资料及其包含的所有信息而创建的目录)。 这意味着用户无法“爬出”他们的配置文件目录,并且偶然地(或有意地)弄乱了任何其他用户的文件。

    仔细检查您是否完全按照所示输入了上述命令-这一步很重要。

    身份验证:用户和计算机帐户

    现在已经配置了Samba并已安装了必需的目录,是时候将用户帐户和计算机帐户添加到域了。 不幸的是,这是一个相当复杂的主题,并且一旦被理解,便是一个乏味的过程。 问题的症结在于Windows密码和UNIX / Linux密码是不同的野兽。 The "bridge" between the two incompatible formats is the Samba password file (in our compiled example, /etc/samba/smbpasswd ). The Samba password file, however, demands a corresponding UNIX account on the same machine. So what we end up with, is two kinds of accounts (user and machine) in two different passwords files (UNIX and Samba, or /etc/passwd and /etc/samba/smbpasswd , respectively).

    The user accounts are self-explanatory and easy to grasp. Machine accounts--which also require entries in both the UNIX and Samba password files--are known as trust accounts (in Windows parlance, computer accounts ). When a trust or machine account is created, a "secret" is automatically generated (similar in concept to a unique machine name/password combination). This secret is used as a means of secure communication between the client and the domain controller, and to prevent an unauthorized machine with the same NetBIOS name from joining the domain and gaining access to data stored there.

    Here's where things get a little tricky. Windows NT/2000/XP clients fully support the concept of trust accounts; Windows 9x/ME clients do not. As a matter of fact, the only concept of domains supported by Windows 9x/ME is the logon mechanism whereby the client will download a system policy if there is one present, and store a profile on the server. Windows 9x/ME has no concept of machine trust or security, which makes it remarkably easy to "spoof" a domain controller into accepting a logon from a Win9X machine that is not who it claims to be. That's why Windows 9x/ME clients are particularly unsuited to domain-type networks. Now that we have that little bit of trivia out of the way, let's move on to creating machine or trust accounts on the PDC. There are two methods available:

    Manual creation where both the UNIX and Samba passwords are added "by hand". Automatic creation via an "add user" script in the smb.conf .

    Machine accounts: the manual approach

    As noted, Samba will not allow you to add an entry to the smbpasswd file (user or machine) unless there is a existing UNIX account for that user. So the first step is to create an entry for the client in /etc/passwd :

    [root@phoenix root]# /usr/sbin/useradd -g machines -d /dev/null -c "machine id" -s /bin/false machine_name$ [root@phoenix root]# passwd -l machine_name$ Changing password for user machine_name$ Locking password for user machine_name$

    The first command creates the user machine_name (don't forget the dollar-sign; it's required and identifies the entry as a trust account)), as a member of the group machines ( -g ), with no home directory ( -d /dev/null ), a descriptive entry ( -c ; for example, "Tom's Notebook"), and no shell access ( -s /bin/false ). The second command creates a "secret" for the machine to authenticate against.

    With the UNIX account created, we can now add the machine to /etc/samba/smbpasswd as shown below:

    [root@phoenix root]# smbpasswd -a -m machine_name Added user machine_name$

    Two things to note in the above command: One, if you installed Samba under /usr/local/samba , you'll probably have to provide the complete path (ie, /usr/local/samba/bin/smbpasswd ). Two, when entering the machine_name, do not append a dollar-sign; it's not required with smbpasswd.

    WARNING: Once a trust account has been created on the PDC, it's good policy to connect the client ASAP (which, in effect, changes the machine "password" and syncs the secret between the server and the client). Until the client formally connects to the PDC, the domain is vulnerable to another machine connecting with the same NetBIOS name.

    Machine accounts: an automated approach

    The second approach to creating machine/trust account on the PDC is to allow Samba to create them as needed when the client first joins the domain. This little bit of magic is accomplished by adding an add user script option to smb.conf . This creates the UNIX trust account, and tells Samba to automatically create a corresponding entry in smbpasswd. The following is an example of an entry based on a Redhat distribution:

    [global] ... add user script = /usr/sbin/useradd -d /dev/null -g machines -s /bin/false -M %u ...

    The important thing to note in the above command is that the command to add users may vary across operating systems and/or distributions, so tweak accordingly.

    Adding user accounts

    The last piece of information we need to provide the PDC is a means of authenticating users. As discussed at the beginning of this section, this is accomplished by adding user accounts to both /etc/passwd and /etc/samba/smbpasswd . Unfortunately, there are no cute configuration options to automate this process (a shell script might ease the tedium). Here are the three commands necessary to create the two required user accounts:

    [root@phoenix root]# useradd leah [root@phoenix root]# passwd leah New password: Retype new password: passwd: all authentication tokens updated successfully [root@phoenix root]# smbpasswd -a leah New SMB password: Retype new SMB password: Added user leah.

    Note that you'll need to create a root user account in order to join Windows NT/2000 machines to the domain. Treat the password you use with the same care and security as you would the UNIX root password; it has all the same authority.

    TIP: I make it a policy to make UIDs the same for all systems on my network; it saves a whole bunch of authentication issues down the road. I also make sure that every user has only one password--that is, I use the same password for UNIX and Samba. Again, it makes for easy system and user management.

    Keeping user accounts in sync

    The last topic of this section is password synchronization. One of the challenges with using Samba is trying to keep user passwords in sync between UNIX and Samba. There is another way of accomplishing this other than going to a backend user-management system like LDAP or NIS. The options statements below will allow a user to change their Samba password from a Windows client, which will in turn update their UNIX password to match the new Samba entry. If the UNIX password is changed, however, the same technique does not work in reverse; the Samba password will have to be manually sync'd.

    [global] ... ;sync UNIX passwords unix password sync = yes passwd program = /usr/bin/passwd %u passwd chat = *New*UNIX*password* %n\n *Retype*new*UNIX*password* %n\n *Enter* new*UNIX*password* %n\n *Retype*new*UNIX*password* %n\n *passwd: *all* authentication*tokens*updated*successfully* ...

    About the only thing that bears mentioning in the above statements is that the passwd chat option, despite how it might display here, is entered on one line. Note also that some options use "password" and others use "passwd".

    Configuration of the Samba PDC is complete. The only thing left to do is join the clients to the domain.

    Client configuration

    Joining clients to the domain

    Unfortunately, there's no easy way around it--joining Windows clients to a domain (assuming, of course, they were not a member of a domain previously) is a hands-on job. If you're lucky enough to be working with a single client across all users, then perhaps a HOWTO could be constructed and circulated, but most administrators are not so blessed. The difficult issue in a mixed-client environment is finding any sort of consistant approach. Every time Microsoft releases a new version of Windows, they also seem to introduce a new way to configure networking. A new dialog here, an extra checkbox there, some systems require you to go through the Control Panel, others by right-clicking on My Computer--all of which makes for a lot of confusion from the user perspective.

    The process is actually relatively painless and mechanical, but it does differ across the gamut of Windows releases. With that in mind, the best approach is to "divide and conquer", which is exactly what we've done here.

    Client configuration: Windows 95/98/ME

    To join a Windows 95/98/ME client to the domain:

    First check that Client for Microsoft Networks is installed; if not, install it ( Control Panel > Network > Client for Microsoft Networks ). To install, place your Windows CD in the drive and select Add from the afforementioned dialog, then: Client > Add... > Microsoft > Client for Microsoft Networks . Make sure Client for Microsoft Networks is the primary network protocol ( Control Panel > Network > Primary Network Logon ). Next, go to Control Panel > Network > Client for Microsoft Networks > Properties > Logon to NT Domain . If you've employed the add user script option, select the checkbox Create a Computer Account in the Domain; otherwise you'll need to ensure a machine account already exists for the client. Fill in the domain, and click OK .

    Client configuration: Windows NT/2000

    Under Windows NT:

    Go to Control Panel > Network > Identification > Change option . If the machine is currently configured under the Workgroup option, select the Domain radio button and enter the domain name. Select Create a Computer Account in the Domain as necessary. Now, logon to the domain using the username root and the appropriate password . This is necessary to initialize the "secret" between the server and client machines. From here forward, any authenticated user can logon from this machine. A message should appear welcoming you to the domain_name domain.

    The steps are the same for Windows 2000 except the network settings are found under Control Panel > System > Network Identification (or right-click the My Computer icon on your desktop, choose Properties , Computer Name , and select the Change button).

    Client configuration: Windows XP

    Enter Windows XP, and the most complex beast of the lot. But first a word of warning for those unaware: Windows XP Home Edition cannot join a Windows domain. For domain functionality, you must use Windows XP Professional. Second, sometimes joining an XP machine to a Samba PDC involved all the steps below; on other occasions, however, you can get away with just the registry patch. Don't ask--I haven't a clue.

    To join a Windows XP machine to a domain:

    Open the Local Security Policy editor ( Start > All Programs > Administrative Tools > Local Security Policy ). Locate the entry "Domain member: Digitally encrypt or sign secure channel (always)". Disable it. Locate the entry "Domain member: Disable machine account password changes". Make sure it's disabled as well. Locate the entry "Domain member: Require strong (Windows 2000 or later) session key". Disable it. Next, download the WinXP_SignOrSeal registry patch from www.samba.org or collect it from the Related topics section at the end of this tutorial. Apply it by double-clicking and answering Yes to the dialog prompt. Now join the domain the same as you would for Windows NT or 2000. Right-click My Computer , select Properties , Computer Name , and Change . Or click the Network ID button and run the Network Wizard.

    Troubleshooting and SWAT information

    When things go bump in the night...

    When Murphy crashes your party, it's time to do some troubleshooting. The list below is by no means complete or seminal. It's simply a compliation of years of working with Samba, and many many hours tracking user's cries for help on the Samba mailing list.

    First and foremost, determine where exactly your problem lies and how it occurred. Is it on the server end, or the client? Did it occur in conjunction with something else? Can you isolate the problem? Did you check your network cables? Are you SURE it's Samba related (this one in particular has bitten me several times), can you perform the same action without difficulty from another workstation? Are the Samba daemons running? If you start the Samba daemons and they unexpectedly die, run the Samba testparm utility on your configuration file. Chances are you have a syntax error somewhere. As a matter of fact, experience has taught me that the two most common errors that cause Samba to stop running or lose functionality are: (1) typos in smb.conf , and (2) incorrect permissions on a file or directory. The client can't save a profile to the PDC? Read the above again. And check your directory permissions. The client can't join the domain? Check to ensure user and machine accounts exist on the controller. If necessary, create them manually. If you try and join the domain, and get a "Cannot join domain..." or "Cannot create account, you already have a connection to the domain" message, check to ensure there are no existing mapped drives to the server. If there are, kill them by typing net use * /d in a command prompt window. If you can't join the domain, and you created the machine account manually, check to ensure you didn't forget to add the dollar-sign ( '$' ) after the machine name. If you can't join the domain, and are using the add user script option to automatically create machine accounts, double check the option. If nothing looks amiss, disable it, and manually create the machine account. Now try again. If all the above fails, go back through the tutorial and double check everything. 有条不紊。 Again, the material presented here has been tripled checked. The smb.conf file was moved to a clean install of Redhat, the directories and permissions were created/set as shown, and the controller was tested with a Windows XP client. Everything worked first time without error or incident. Finally, failing everything else, send a message to the Samba mailing list asking for assistance. Don't forget to detail your problem clearly, what you've tried so far, and enclose your configuration file. The list is populated by a lot of very fine people; someone will no doubt come to your rescue.

    Sidebar I: SWAT

    A lot of administrators accustomed to GUI configuration tools find working with a command line editor like vi or emacs both intimidating and frustrating. Situations like this are precisely what SWAT was designed to address. SWAT stands for Samba Web Administration Tool, and is bundled with the Samba package. In short, SWAT puts an easy to navigate interface on smb.conf using any web browser. It also provides context-sensitive help for all options, and a link to the vast array of documentation shipped with Samba.

    Unfortunately, convenience always comes at a cost. First and foremost, SWAT requires the root password to accomplish much of anything, and that password is transmitted in plain text. This dangerous security breach is offset somewhat by the fact that SSL/HTTPS can be used for remote connections (there's a HOWTO located at www.samba.org/samba/docs/swat_ssl.html ). Second, SWAT has a habit of rearranging the order of entries in smb.conf when changes are saved. If you've got a carefully ordered configuration file complete with insightful comments, I do not recommend using SWAT.

    Another difficulty with SWAT is that it's turned off by default and users unfamiliar with the landscape of Redhat seem to have a lot of trouble turning it on. This last problem is easy to fix.

    Sidebar II: SWAT configuration

    The are two ways to enable SWAT, depending on whether your system is configured to use xinetd or inetd .

    For systems running xinetd (RH 7.2 and, I believe, 7.1), the script /etc/xinetd.d/swat must be edited (as root). Change the line that reads disable = yes to disable = no . If you want to access SWAT from a remote machine (a very bad choice on anything but a firewalled intranet), place a pound sign ( '#' ) in front of the line that reads only_from = localhost. Now re-start the xinetd daemon by typing service xinetd reload (again, as root). You should now be able to access the SWAT service directly from the local machine by typing httpd://localhost:901 , or from a remote host by substituting localhost for the host name.

    On systems running inetd, two files must be edited. Ensure that /etc/services contains the line:

    swat 901/tcp

    Next, open /etc/inetd.conf and locate the line that reads:

    swat stream tcp nowait.400 root /path/to/the/swat/binary swat

    Replace /path/to/the/swat/binary with the correct path. For example, /usr/sbin/swat . Now restart the inetd service: service inetd reload. Follow the procedures in the paragraph above to connect to your server.

    Wrapping up

    摘要

    This tutorial stepped through the process of configuring Samba to assume the role of primary domain controller on a local network. The following topics were discussed:

    A brief glance into the history and importance of the Samba project, what Samba can do, what it can't do, what hardware components are pivitol to good performance, and how to best utilize the material presented. How to install Samba from RPM or source, how to configure the build process to ensure directory and file placement, and how to configure smb.conf to be a PDC, support roaming profiles, and support netlogons. How to create the required administrative directories on the server, set the correct permissions on those directories, and how to create the two sets (UNIX and Samba) of user and machine accounts for authentication. How to configure Windows 95/98/ME/2000/XP clients to joint the domain. How to troubleshoot an installation that doesn't work as advertised. And finally, where to find further Samba resources.

    I hope in the course of working through this tutorial you found what you were looking for, and --ideally -- some things you weren't. I know I sure did. And that, in the end, is what life's all about. Learning new things and pushing the boundries.


    翻译自: https://www.ibm.com/developerworks/aix/tutorials/samba/samba.html

    相关资源:samba-swat-3.0.33-3.39.el5_8.i386.rpm
    Processed: 0.012, SQL: 9