赞
踩
/etc/samba/smb.conf
vi /etc/samba/smb.conf
Samba的配置文件是/etc/samba/smb.conf
,这个文件包含了Samba服务器的各种配置参数,用于定义Samba服务器的行为、共享资源、安全设置等。以下是对/etc/samba/smb.conf
配置文件的一些关键点和配置的详细解释:
workgroup:指定Samba服务器所在的工作组名称。这允许Samba服务器与其他计算机在同一工作组中进行通信和共享资源。
server string:设定Samba服务器的注释,可以是任何字符串,用于向客户端提供有关服务器的信息。默认可能显示Samba的版本号,但建议修改为更具描述性的信息以防止潜在的版本攻击。
security:指定Samba服务器的安全模式,可以是user
、share
、server
或domain
等。不同的模式提供了不同的身份验证和访问控制机制。
user
:最常用的模式,要求用户提供用户名和密码进行身份验证。share
:匿名访问模式,用户无需提供用户名和密码即可访问共享资源。server
:基于验证身份的访问,但账户信息保存在另一台SMB服务器上。domain
:域安全级别,使用主域控制器(PDC)来完成认证。interfaces:设置Samba服务器监听哪些网络接口。可以指定网卡名或IP地址。
hosts allow/hosts deny:指定哪些主机或网段被允许或拒绝访问Samba服务器。这两个参数可以灵活地控制访问权限。
log file 和 max log size:设置Samba服务器日志文件的存储位置和最大容量。日志文件对于故障排查和监控访问活动非常有用。
passdb backend:用户后台的意思,指定用户和密码的存储方式,如smbpasswd
、tdbsam
和ldapsam
等。
共享段特定配置:
read list
和write list
来更精细地控制读写权限,但并非所有版本都支持这些选项。如果不支持,可以通过valid users
和writable
的组合来实现类似效果)。@
开头例如
[shared]
path = /srv/samba/shared
browsable = yes
writable = yes
valid users = @salesgroup, @marketing
admin users = administrator
%S
任何可登陆的用户均可登陆%m
客户端的netbios主机名%M
客户端hostname%L
smb主机的netbios主机名%h
smb主机的hostname%H
用户的默认目录%U
目前登陆的用户名%g
登陆用户的群组名%I
客户端的ip%T
目前的日期与时间配置完/etc/samba/smb.conf
文件后,可以使用testparm
命令来测试配置文件的语法是否正确,并查看配置参数的详细列表。例如:
testparm /etc/samba/smb.conf
这个命令会列出所有配置段和参数,帮助管理员验证配置是否正确。
/etc/samba/smb.conf
文件时,建议使用文本编辑器(如nano
、vim
等)进行,并确保备份原始文件以防万一。systemctl restart smbd
或service smbd restart
等命令。Samba的配置文件/etc/samba/smb.conf
中,可以使用一系列预定义的变量来动态地设置配置选项的值。这些变量在配置文件中被解析时,会根据当前的上下文(如当前的服务、用户、会话等)替换为相应的实际值。以下是一些常用的Samba配置变量及其说明:
%S:当前服务名(Service Name)。这个变量会被替换为当前正在被访问的共享服务的名称。
%P:当前服务的根目录(Service Root Path)。这个变量表示共享服务的本地文件系统中的根目录路径。
%u:当前服务的用户名(User Name)。这个变量在需要时会被替换为访问当前共享服务的用户的用户名。
%U:当前会话的用户名(Session User Name)。在某些情况下,这个变量与%u
类似,但在某些特定的上下文(如会话)中可能有所不同。
%g:当前服务用户所在的主工作组(Primary Group Name)。这个变量表示用户所属的主工作组的名称。
%G:当前会话用户所在的主工作组(Session Primary Group Name)。与%g
类似,但在会话上下文中可能有所不同。
%H:当前服务的用户的Home目录(Home Directory)。如果共享服务与用户的主目录相关联,这个变量会被替换为该用户的Home目录路径。
%V:samba的版本号(Samba Version)。这个变量会被替换为Samba服务的版本号。
%h:运行samba服务机器的主机名(Host Name)。这个变量会被替换为运行Samba服务的服务器的主机名。
%M:客户端的主机名(Client Machine Name)。这个变量在需要时会被替换为访问Samba服务器的客户端的主机名。
%m:客户端的NetBIOS名称(Client NetBIOS Name)。在某些情况下,这个变量会提供客户端的NetBIOS名称。
%L:服务器的NetBIOS名称(Server NetBIOS Name)。这个变量表示运行Samba服务的服务器的NetBIOS名称。
%R:所采用的协议等级(Protocol Level)。这个变量会表示客户端和服务器之间通信所采用的协议等级。
%d:当前服务进程的ID(Process ID)。这个变量在需要时会被替换为处理当前请求的Samba服务进程的ID。
%I:客户端的IP地址(Client IP Address)。这个变量会提供访问Samba服务器的客户端的IP地址。
%T:当前日期和时间(Current Date and Time)。这个变量会被替换为当前的日期和时间。
这些变量在配置文件中非常有用,因为它们允许管理员编写更加灵活和动态的配置,而无需为每个共享资源或服务硬编码特定的值。例如,可以使用%P
变量来动态地设置共享服务的根目录,或者使用%u
变量来限制特定用户对其主目录的访问。
请注意,这些变量的具体可用性和行为可能会因Samba的版本和配置而有所不同。因此,在编写Samba配置文件时,建议参考官方文档以获取最准确和最新的信息。
[global]
在 Samba 的 smb.conf
配置文件中,[global]
部分包含了影响整个 Samba 服务器的全局设置。这些设置定义了 Samba 服务器的行为、安全性、日志记录、网络参数等。以下是一些常见的 [global]
部分中的配置项:
workgroup = WORKGROUP
WORKGROUP
,但你可以根据你的网络设置进行修改。server string = %h server (Samba, Ubuntu)
%h
会被替换为服务器的主机名。interfaces = 127.0.0.0/8 eth0
bind interfaces only = yes
interfaces
被设置时,这个选项会强制 Samba 只监听在 interfaces
中指定的网络接口。hosts allow = 192.168.1. 127.
hosts deny = 0.0.0.0/0
hosts allow
和 hosts deny
可以一起使用,但 hosts deny
会在 hosts allow
之后评估。security = user
user
是最常用的模式,要求用户进行身份验证。passdb backend = tdbsam
tdbsam
是 Samba 自带的基于文件的密码数据库。encrypt passwords = yes
user
),这个选项会启用密码加密。smb passwd file = /etc/samba/smbpasswd
username map = /etc/samba/smbusers
guest account = nobody
log file = /var/log/samba/log.%m
%m
会被替换为客户端的主机名或 IP 地址,这有助于区分来自不同客户端的日志条目。max log size = 1000
load printers = yes/no
printing = cups
cups
是大多数 Linux 发行版上使用的打印系统。请注意,这只是一个 [global]
部分中可能包含的配置项的子集。根据你的具体需求和安全策略,你可能需要调整或添加其他配置项。此外,不同的 Samba 版本可能支持不同的配置项和选项值,因此建议查阅你所使用的 Samba 版本的官方文档以获取最准确的信息。
security
在 Samba 的配置文件 smb.conf
中,[global]
部分包含了影响整个 Samba 服务器的全局设置。其中,security
参数是一个非常重要的配置项,它决定了 Samba 服务器如何验证用户访问共享资源。
security
参数可以有以下几种设置:
share(共享模式):
user(用户模式):
/etc/samba/smbpasswd
文件或系统用户),也可以是远程的(如通过 LDAP、Kerberos 或 Windows AD 等服务)。server(服务器模式):
domain(域模式):
ads(Active Directory 服务模式):
domain
模式,但更具体地指向 Microsoft 的 Active Directory 服务。在这种模式下,Samba 服务器被配置为 Active Directory 域的成员,并使用 AD 进行用户身份验证。这是将 Samba 服务器集成到大型 Windows 网络环境中的一种有效方式。选择哪种 security
模式取决于你的网络环境和安全需求。例如,如果你正在设置一个小型家庭网络,并且不需要复杂的用户验证,那么 share
模式可能就足够了。然而,在商业环境中,你可能需要 user
、domain
或 ads
模式来确保更安全的用户访问控制。
在配置 Samba 时,请确保 smb.conf
文件中的 security
参数设置符合你的需求,并相应地调整其他相关配置,如用户映射、密码文件位置等。
passdb backend
在 Samba 的 smb.conf
配置文件中,[global]
部分的 passdb backend
参数用于指定 Samba 服务用于存储和检索用户密码的后端数据库类型。这个参数对于用户验证过程至关重要,因为它决定了 Samba 如何查找和验证用户提供的密码。
passdb backend
可以有以下几种设置:
smbpasswd:
/etc/samba/smbpasswd
文件中(或者由 smb passwd file
参数指定的其他文件中)。然而,这种方式的性能可能不如基于数据库的后端,并且在多服务器环境中同步密码可能会更加复杂。tdbsam:
/var/lib/samba/private/passwd.tdb
(或类似的路径,具体取决于 Samba 的配置和安装位置)。ldapsam:
ldapsam
作为密码后端。这种方式允许 Samba 从 LDAP 目录中检索用户信息和密码,从而实现了与现有目录服务的无缝集成。这对于需要将 Samba 集成到大型网络或企业环境中的情况特别有用。pdbedit:
pdbedit
本身并不是 passdb backend
的一个直接选项,但它是一个用于管理 Samba 密码数据库的工具。无论使用哪种 passdb backend
,pdbedit
都可以用来添加、删除、列出和修改 Samba 用户密码。在配置 passdb backend
时,你应该根据你的网络环境和安全需求来选择最合适的后端类型。如果你正在设置一个小型网络,并且不需要与现有的目录服务集成,那么 tdbsam
可能是一个很好的选择。然而,如果你需要将 Samba 集成到大型网络或企业环境中,那么 ldapsam
可能更适合你的需求。
请注意,更改 passdb backend
可能需要额外的配置步骤,并且可能需要重新初始化密码数据库。因此,在更改此设置之前,请务必备份你的 Samba 配置文件和任何相关的密码数据库文件。
此外,不同的 Samba 版本可能支持不同的 passdb backend
选项和配置方法。因此,在配置 Samba 时,请务必参考你所使用的 Samba 版本的官方文档以获取最准确的信息。
map to guest
在 Samba 的 smb.conf
配置文件的 [global]
部分,map to guest
参数用于控制当用户无法通过正常的用户验证流程进行认证时,是否应该将这些用户映射为 guest 用户。这个参数在配置 Samba 服务器时非常重要,因为它决定了匿名访问的策略。
map to guest
参数详解map to guest
参数决定了 Samba 是否将这些用户视为 guest 用户,并允许他们根据 guest 用户的权限进行访问。map to guest
参数通常设置为 Bad User
或 yes
。
Bad User
时,表示所有无法通过正常认证流程识别的用户都将被映射为 guest 用户。这意味着,如果 Samba 无法在其用户数据库中找到用户提供的用户名,或者该用户提供的密码不正确,该用户将被视为 guest 用户。map to guest = yes
的设置,但现代 Samba 版本更推荐使用 Bad User
作为值,因为它提供了更明确的控制。然而,请注意,直接设置为 yes
的行为可能因 Samba 版本而异,因此建议查阅具体版本的 Samba 文档以获取准确信息。map to guest
参数后,匿名用户(即那些未通过正常认证流程的用户)将能够访问 Samba 服务器上的共享资源,但他们的访问权限将受到 guest 用户权限的限制。这通常意味着他们只能读取共享资源,而不能进行修改或删除等操作。map to guest
参数)可能会降低 Samba 服务器的安全性。因此,在配置此参数时,请务必考虑到你的安全需求,并确保你了解匿名访问可能带来的风险。map to guest
参数的具体实现和默认值上存在差异。因此,在配置 Samba 服务器时,请务必参考你所使用的 Samba 版本的官方文档。map to guest
参数外,Samba 的 smb.conf
配置文件中还有许多其他参数可以影响匿名访问和用户认证的行为。在配置 Samba 服务器时,请务必全面了解这些参数,并根据你的需求进行适当设置。在 Samba 的 smb.conf
配置文件的 [global]
部分中,map to guest
参数用于控制当用户无法通过正常认证流程进行访问时是否应该将这些用户映射为 guest 用户。建议根据你的安全需求和 Samba 版本的官方文档来配置此参数。
load printers
在 Samba 的配置文件 /etc/samba/smb.conf
中,load printers = yes
这一行是用来控制 Samba 是否应该加载系统上的打印机以供网络共享。当设置为 yes
时,Samba 会尝试自动检测并共享所有已安装的本地打印机。这对于在局域网中共享打印机资源非常有用。
load printers = yes:启用此选项后,Samba 守护进程(通常是 smbd
和 nmbd
)会在启动时尝试自动发现和加载本地系统上的所有打印机。然后,这些打印机就可以通过 Samba 服务被网络上的其他客户端访问和使用。
注意:为了使打印机通过 Samba 成功共享,除了设置 load printers = yes
之外,还需要确保 Samba 用户有权访问这些打印机,以及 Samba 服务的配置正确无误。此外,打印机的驱动程序也需要与客户端操作系统兼容。
下面是一个简单的 smb.conf
配置文件片段,展示了如何启用打印机共享:
[global] workgroup = WORKGROUP server string = Samba Server Version %v security = user map to guest = bad user dns proxy = no load printers = yes cups options = raw [printers] comment = All Printers path = /var/spool/samba browseable = no guest ok = no writable = no printable = yes printer admin = @admingroup create mask = 0700
在这个配置中,[global]
部分设置了 load printers = yes
来启用打印机共享。此外,还有一个 [printers]
共享部分,它专门用于控制对共享打印机的访问。这里,printable = yes
表明这个共享是用于打印的,而 path
指向的是 Samba 用于处理打印作业的临时文件存储位置(尽管对于 CUPS 管理的打印机,这个路径通常不是必须的)。
/var/log/samba/
),以获取有关错误和警告的详细信息。cups options
在 Samba 的配置文件 /etc/samba/smb.conf
中,[global]
部分下的 cups options
参数用于控制 Samba 如何与 CUPS(Common UNIX Printing System)进行交互,特别是当 Samba 被配置为共享打印机时。cups options
参数允许你设置一些选项,以影响 Samba 如何处理打印作业。
然而,需要注意的是,cups options
参数的具体用法和可接受的选项可能会根据你使用的 Samba 和 CUPS 版本而有所不同。在较新版本的 Samba 中,cups options
的使用可能已经变得不那么常见,因为 Samba 可能会使用更现代的机制来与 CUPS 集成。
但是,在一些配置中,你可能会看到 cups options
被设置为 raw
,这通常意味着 Samba 将以原始模式(raw mode)向 CUPS 发送打印作业。在原始模式下,Samba 不会尝试对打印作业进行任何格式转换或处理,而是直接将其传递给 CUPS。这对于某些需要特定格式或不需要 Samba 进行额外处理的打印机来说可能是必要的。
然而,在大多数情况下,如果你只是想要简单地共享打印机并让 Samba 与 CUPS 正常协作,你可能不需要显式地设置 cups options
。Samba 和 CUPS 之间的集成通常是自动的,并且会根据你的系统配置和 Samba 的默认设置来工作。
如果你确实需要设置 cups options
,并且你正在使用的 Samba 版本支持该参数,你可以按照类似以下的方式在 smb.conf
的 [global]
部分中进行配置:
[global]
workgroup = WORKGROUP
server string = Samba Server %v
...
cups options = raw
...
但是,请记住,这只是一个示例,并且你可能需要根据你的具体需求和 Samba/CUPS 的版本来调整设置。
如果你不确定如何配置 cups options
或其他与打印相关的 Samba 参数,建议查阅你所使用的 Samba 和 CUPS 版本的官方文档。这些文档将提供有关如何配置 Samba 以与 CUPS 协作的详细信息,以及可用的选项和参数的完整列表。
此外,如果你遇到与打印相关的问题,并且你怀疑这可能是由 Samba 的配置引起的,请检查 Samba 的日志文件(通常位于 /var/log/samba/
),以获取有关错误和警告的详细信息。这些日志信息可以帮助你诊断问题,并确定是否需要调整 Samba 的配置。
public
和 guest ok
在Samba的配置文件/etc/samba/smb.conf
中,public
和guest ok
是两个重要的参数,它们分别用于控制共享资源的访问权限,特别是在处理匿名访问时。以下是对这两个参数的详细解释:
public
参数主要用于定义一个共享是否对公共访问开放。然而,需要注意的是,在较新版本的Samba配置中,public
参数可能并不直接出现,或者其使用方式已经有所变化。在一些情况下,public
参数可能被视为过时的,或者其功能被其他参数(如guest ok
和map to guest
)所取代。public
被设置为yes
,则意味着共享资源对所有人开放,无需身份验证即可访问。但是,这种用法在现代Samba配置中可能不再被推荐,因为它可能带来安全风险。guest ok
和map to guest
等参数来控制匿名访问。guest ok = yes
允许匿名访问,而map to guest
则定义了当无法验证用户身份时应如何处理(例如,映射为特定的guest用户)。guest ok
参数用于指定是否允许匿名访问Samba共享。这是控制共享资源访问权限的关键参数之一。yes
:允许匿名访问。即,用户无需提供用户名和密码即可访问共享资源。这通常用于提供公共文件或资源,如文档、图片等。no
:不允许匿名访问。用户必须提供有效的用户名和密码才能访问共享资源。这提高了共享资源的安全性。guest ok
时,请务必考虑到你的安全需求,并确保你了解匿名访问可能带来的风险。以下是一个简化的smb.conf
配置文件片段,展示了如何配置guest ok
来控制匿名访问:
[global]
workgroup = WORKGROUP
server string = Samba Server %v
...
[sharedir]
path = /path/to/shared/directory
guest ok = yes ; 允许匿名访问
; 其他配置...
[securedir]
path = /path/to/secure/directory
guest ok = no ; 不允许匿名访问
valid users = user1,user2 ; 限定只有user1和user2可以访问
; 其他配置...
在这个示例中,[sharedir]
共享允许匿名访问,而[securedir]
共享则要求用户提供有效的用户名和密码才能访问。
guest ok
之外,Samba还提供了其他多个参数来控制访问权限和安全性,如valid users
、read only
、writeable
等。在配置Samba服务器时,可以根据需要合理使用这些参数来增强安全性。public
在 Samba 的配置文件 /etc/samba/smb.conf
中,public
这个参数并不直接作为 [global]
部分的一个标准选项出现。实际上,在较新版本的 Samba 配置中,你可能不会看到 public
这个明确的参数,因为 Samba 提供了其他更细粒度的参数来控制共享资源的访问权限。
然而,在一些旧版本的 Samba 文档或教程中,你可能会遇到 public
这个术语,它通常被用来描述一个共享是否对所有人开放,无需身份验证即可访问。但是,这种描述并不直接对应于 smb.conf
文件中的一个具体参数。
在 Samba 的上下文中,要控制一个共享是否允许匿名访问(即“公共”访问),你通常会使用 guest ok
参数。当 guest ok
设置为 yes
时,该共享允许匿名访问;当设置为 no
时,则不允许匿名访问,用户必须提供有效的用户名和密码才能访问。
如果你想要配置一个“公共”共享,即任何人都可以访问的共享,你应该在相应的共享定义部分(而不是 [global]
部分)中设置 guest ok = yes
。此外,为了安全起见,你可能还希望设置 read only = yes
(如果你希望该共享是只读的),以及通过 valid users
或 invalid users
参数来进一步限制访问(尽管在 guest ok = yes
的情况下,这些参数通常不会影响匿名访问的能力)。
请注意,虽然 public
这个词在 Samba 的上下文中可能会被提及,但它并不是 smb.conf
文件中的一个实际参数。相反,你应该使用 Samba 提供的具体参数(如 guest ok
、read only
、valid users
等)来配置你的共享资源。
如果你正在查看的 Samba 文档或教程中提到了 public
,那么它可能是在以一种非技术性的方式描述共享资源的访问权限,或者它可能是在引用某个特定于该文档或教程的自定义参数或配置约定。然而,在标准的 Samba 配置中,你应该使用 Samba 官方文档中描述的参数来控制共享资源的访问权限。
guest ok
在Samba的配置文件/etc/samba/smb.conf
中,guest ok
参数用于指定是否允许匿名访问共享资源。以下是关于guest ok
参数的详细解释:
guest ok
参数的作用guest ok
参数决定了未经身份验证的用户是否可以以匿名方式访问Samba服务器上的共享资源。guest ok
参数的设置选项yes
时,允许未经身份验证的用户以匿名方式访问共享资源。这适用于需要向公众提供某些共享资源,而不需要用户进行身份验证的场景。no
时,只有经过身份验证的用户才能访问共享资源。这提高了资源的安全性,确保只有授权的用户才能访问敏感信息。在/etc/samba/smb.conf
文件中,guest ok
参数通常位于共享资源的配置段中,如下所示:
[共享名]
path = /path/to/shared/folder
browsable = yes
writable = yes
guest ok = yes ; 允许匿名访问
; 其他参数...
或者,如果希望禁止匿名访问,则可以将guest ok
设置为no
:
[共享名]
path = /path/to/shared/folder
browsable = yes
writable = yes
guest ok = no ; 禁止匿名访问
; 其他参数...
guest ok
参数可以针对不同的共享资源单独设置,以满足不同的访问需求。guest ok
参数的基本用法和功能是保持一致的。guest ok
参数是Samba配置文件中用于控制匿名访问共享资源的重要参数。通过合理设置该参数,可以灵活地管理对共享资源的访问权限,确保系统的安全性和可用性。
map to guest
在 Samba 的配置文件 /etc/samba/smb.conf
中,map to guest
指令是一个非常有用的设置,它允许 Samba 服务器将特定的用户或用户组映射为来宾(guest)用户。这对于控制对共享资源的访问特别有用,尤其是当你想要限制或简化对共享文件夹的访问权限时。
map to guest
指令可以在 [global]
部分或特定的共享部分(如 [sharename]
)中设置。当在 [global]
部分设置时,它将影响所有未明确指定 guest ok = yes
或 map to guest
的共享。
当map to guest = yes
启用时,未授权的访客会被自动映射到一个匿名用户(通常是noguest),允许他们只读访问某些共享资源。如果设置为no或默认值,则不允许匿名访问,除非有明确的来宾账户设置。
[global]
部分设置:影响所有共享,除非在共享部分另有指定。[global]
部分设置[global]
workgroup = MYGROUP
server string = Samba Server %v
map to guest = Bad User
security = user
这里,map to guest = Bad User
意味着任何未能在 Samba 服务器上找到的用户账户都将被映射为来宾用户。这通常用于增强安全性,因为它阻止了未授权用户通过猜测有效用户名来访问系统。
[public]
path = /srv/samba/public
browsable = yes
writable = yes
guest ok = yes
map to guest = Bad Password
在这个例子中,[public]
共享允许所有用户作为来宾访问,但 map to guest = Bad Password
的设置确保了任何试图以非来宾身份访问的用户(即使提供了密码),如果其密码验证失败,也会被映射为来宾用户。注意,这里的 Bad Password
并不是字面意思上的“错误的密码”,而是一个指令,告诉 Samba 将这类用户视为来宾。
map to guest
指令和 guest ok = yes
常常一起使用,但它们的作用不同。guest ok = yes
允许来宾访问共享,而 map to guest
则定义了哪些用户或用户组应该被映射为来宾。map to guest
时,请确保理解其含义和后果,因为它可能会无意中放宽对共享资源的访问控制。security
项在Samba的配置文件/etc/samba/smb.conf
中,security
项是一个非常重要的配置项,它用于指定Samba服务器的安全模式,即控制Samba服务器对用户身份验证和访问权限的管理方式。security
项可以设置为以下几种模式之一:
user:
share:
server:
domain:
security
项时,需要根据实际的安全需求和访问控制策略来选择适当的模式。security
模式可能会影响到其他配置项的设置和效果,因此在调整security
项时,也需要考虑其他相关配置。security
项外,还需要关注密码策略、用户访问控制、防火墙规则、加密通信、日志和监控等方面的配置,以确保Samba服务器的安全性。在/etc/samba/smb.conf
文件中设置security
项的一个示例如下:
[global]
security = user
...
在这个示例中,security
项被设置为user
,表示Samba服务器将使用系统上的用户账号和密码进行身份验证。
security
项在Samba配置中扮演着至关重要的角色,它决定了Samba服务器的安全模式,从而影响到用户身份验证和访问权限的管理方式。正确设置security
项是确保Samba服务器安全性和访问控制策略的关键步骤之一。
available
在 Samba 的配置文件 /etc/samba/smb.conf
中,available
参数用于指定某个共享资源是否可用。当设置为 yes
时,该共享资源对用户是可见的,可以被访问;当设置为 no
时,该共享资源则对用户隐藏,不可访问。
然而,需要注意的是,available
参数并不是 Samba 配置文件中的标准或必选参数。在某些 Samba 的版本或配置环境中,可能并不直接支持 available
参数。相反,共享资源的可用性可能通过其他方式控制,如共享名称的存在与否、路径的可访问性等。
在 Samba 的配置文件中,共享资源的定义通常是通过一个或多个以方括号 []
包围的段(section)来实现的。每个段代表一个共享资源,段内的参数定义了该共享资源的各种属性。如果要在配置文件中控制某个共享资源的可用性,通常的做法是在该共享资源的定义段中添加或修改相应的参数,如 path
(指定共享资源的物理路径)、read only
(指定共享是否只读)、writeable
(指定共享是否可写)等。
然而,如果确实需要在 Samba 配置文件中明确指定某个共享资源的可用性,并且发现 available
参数被支持(这可能取决于 Samba 的具体版本或第三方扩展),则可以按照以下方式设置:
[共享名]
path = /path/to/shared/folder
browsable = yes
writable = yes
available = yes ; 指定该共享资源可用
; 其他参数...
或者,如果希望隐藏该共享资源:
[共享名]
path = /path/to/shared/folder
browsable = no
writable = no
available = no ; 显式指定该共享资源不可用(但通常只设置 browsable = no 就足够了)
; 注意:在某些情况下,即使 available = no,如果 browsable = yes 且其他条件满足,共享仍可能间接可见
; 其他参数...
但请注意,由于 available
参数可能不是所有 Samba 版本的标准参数,因此在配置之前最好查阅您所使用的 Samba 版本的官方文档或相关资源,以确认该参数的支持情况和正确用法。
如果官方文档中没有提到 available
参数,或者您发现它不起作用,那么可能需要考虑使用其他方法来控制共享资源的可用性,比如通过操作系统的文件权限、SELinux 策略、iptables 规则等。
browsable
在 Samba 的配置文件 /etc/samba/smb.conf
中,browsable
参数用于指定共享资源是否可以在网络浏览器或文件管理器中浏览。这是一个重要的配置选项,它控制着共享资源在网络上的可见性。
browsable = yes
时:共享资源会在网络浏览器或文件管理器中显示,允许其他计算机上的用户浏览和访问该共享资源中的文件和文件夹。browsable = no
时:共享资源不会在网络浏览器或文件管理器中显示,但知道确切路径的用户仍然可以通过直接输入路径来访问该共享资源(如果其他权限设置允许的话)。browsable
设置为 no
。browsable = no
可以简化网络浏览器中的视图,使用户更容易找到和访问常用的共享资源。在 /etc/samba/smb.conf
文件中,共享资源的定义通常是通过一个或多个以方括号 []
包围的段(section)来实现的。每个段代表一个共享资源,段内的参数定义了该共享资源的各种属性。以下是包含 browsable
参数的示例配置:
[Public]
path = /srv/samba/public
browsable = yes
writable = yes
guest ok = yes
[Private]
path = /srv/samba/private
browsable = no
writable = yes
valid users = @staff
在这个示例中,Public
共享资源是可浏览的,任何用户(包括匿名用户,如果 guest ok = yes
)都可以在网络浏览器中找到并访问它。而 Private
共享资源则不可浏览,只有属于 staff
组的用户(通过 valid users = @staff
指定)才能通过直接输入路径来访问它。
/etc/samba/smb.conf
文件后,需要重启 Samba 服务或重新加载配置文件以使更改生效。browsable = no
时,请确保了解这样做的影响,并确保知道如何直接访问这些不可浏览的共享资源。read only
项在Samba的配置文件/etc/samba/smb.conf
中,read only
项是一个关键的配置项,用于指定共享资源是否只读。以下是对read only
项的详细解释:
read only
项的作用read only = yes
时,共享资源被设置为只读模式。这意味着连接到该共享资源的用户只能读取文件,不能修改、删除或创建新文件。read only = no
(或者没有设置read only
项,因为默认可能是no
,具体取决于Samba的版本和配置文件的其他部分)时,共享资源允许读写操作。用户可以读取、修改、删除或创建文件。valid users
、write list
等),可以更精细地控制哪些用户可以读取或写入共享资源。在/etc/samba/smb.conf
文件中,共享资源的定义通常是通过一个或多个以方括号[]
包围的段(section)来实现的。每个段代表一个共享资源,段内的参数定义了该共享资源的各种属性。以下是包含read only
项的示例配置:
[Documents]
path = /srv/samba/documents
browsable = yes
read only = yes ; 设置为只读模式
valid users = @staff ; 只有staff组的用户可以访问
[Projects]
path = /srv/samba/projects
browsable = yes
read only = no ; 设置为读写模式
valid users = @developers ; 只有developers组的用户可以访问
write list = @admins ; 只有admins组的用户可以在此共享中写入数据
在这个示例中,Documents
共享资源被设置为只读模式,只有属于staff
组的用户可以访问它,但无法修改其中的文件。而Projects
共享资源则允许读写操作,但只有属于developers
组的用户可以访问它,并且只有属于admins
组的用户可以在其中写入数据。
/etc/samba/smb.conf
文件后,需要重启Samba服务或重新加载配置文件以使更改生效。read only
项时,请确保了解这样做的影响,并根据实际需求进行配置。writable
项在Samba的配置文件/etc/samba/smb.conf
中,writable
项是一个重要的配置项,用于指定共享资源是否允许写入操作。然而,需要注意的是,在不同的Samba版本和配置文件中,可能会看到writable
项或其等效项(如read only
)的使用。
writable
项的作用writable = yes
时,共享资源被设置为可写模式。这意味着连接到该共享资源的用户可以在共享目录中创建、修改和删除文件。writable
项并不直接设置为no
来启用只读模式,而是通过read only = yes
来实现。但是,如果writable
项被明确设置为yes
,并且没有设置read only = yes
,则共享资源默认为可写。在/etc/samba/smb.conf
文件中,共享资源的定义通常是通过一个或多个以方括号[]
包围的段(section)来实现的。每个段代表一个共享资源,段内的参数定义了该共享资源的各种属性。以下是包含writable
(或read only
)项的示例配置:
[SharedDocs]
path = /srv/samba/shared
browsable = yes
writable = yes ; 设置为可写模式
valid users = @staff ; 只有staff组的用户可以访问
[ReadOnlyData]
path = /srv/samba/readonly
browsable = yes
read only = yes ; 设置为只读模式
guest ok = yes ; 允许匿名访问(可选)
在这个示例中,SharedDocs
共享资源被设置为可写模式,只有属于staff
组的用户可以访问并修改其中的文件。而ReadOnlyData
共享资源则被设置为只读模式,任何用户(包括匿名用户,如果guest ok = yes
被设置)都可以访问但无法修改其中的文件。
/etc/samba/smb.conf
文件后,需要重启Samba服务或重新加载配置文件以使更改生效。writable
或read only
项时,请确保了解这样做的影响,并根据实际需求进行配置。此外,需要注意的是,在某些Samba版本中,writable
项可能不是直接可用的,而是通过read only
项的反向逻辑来实现可写或只读的控制。因此,在配置时,请务必参考您所使用的Samba版本的官方文档或相关资源。
directory mask
项在Samba的配置文件/etc/samba/smb.conf
中,directory mask
项是一个重要的配置项,它用于设置新创建的目录的默认Unix权限。这些权限决定了谁可以访问、修改或删除这些目录。
directory mask
项的作用directory mask
项的设置。这有助于确保新创建的目录具有适当的访问控制。在/etc/samba/smb.conf
文件中,您可能会看到类似以下的配置段(section),其中包含了directory mask
项:
[ShareName]
path = /path/to/share
browsable = yes
writable = yes
valid users = user1,user2
directory mask = 0777
...
在这个示例中,ShareName
是共享资源的名称,/path/to/share
是共享资源的路径。directory mask = 0777
指定了新创建的目录将具有最宽松的权限设置,即所有用户都可以读、写和执行这些目录。然而,需要注意的是,这种设置可能会带来安全风险,因为它允许任何用户修改或删除目录中的内容。
directory mask 是一个设置选项,它用于指定新建目录时自动应用的权限掩码。这个值是一个八进制数字,通常表示的是对文件和目录的权限组合,比如0755(rwxr-xr-x)。当用户创建新的共享目录时,如果没有明确的其他权限设置,directory mask 将决定默认的权限分配。
例如,如果设置为 directory mask = 0775,那么新创建的目录将具有所有者有读、写和执行权限(rwx),组和其他用户只有读和执行权限(rw-)。这对于控制共享资源的安全性和访问级别很有帮助。
create mask
项在Samba的配置文件/etc/samba/smb.conf
中,create mask
项是一个关键的配置项,它用于设置新创建文件的默认Unix权限。这些权限决定了谁可以访问、读取、写入或执行这些文件。
create mask
项的作用create mask
项的设置。这有助于确保新创建的文件具有适当的访问控制。在/etc/samba/smb.conf
文件中,您可能会看到类似以下的配置段(section),其中包含了create mask
项:
[ShareName]
path = /path/to/share
browsable = yes
writable = yes
valid users = user1,user2
create mask = 0664
...
在这个示例中,ShareName
是共享资源的名称,/path/to/share
是共享资源的路径。create mask = 0664
指定了新创建的文件将具有以下权限设置:
create mask
时,请确保不会授予过多的权限给不需要的用户。根据实际需求来设置适当的权限,以平衡访问性和安全性。/etc/samba/smb.conf
文件后,需要重启Samba服务或重新加载配置文件以使更改生效。create mask
项在Samba配置中用于设置新创建文件的默认Unix权限。正确设置这些权限对于确保共享资源的安全性和可访问性至关重要。
valid users
项在Samba的配置文件/etc/samba/smb.conf
中,valid users
项是一个重要的配置项,它用于指定哪些用户被允许访问特定的共享资源。这个配置项在共享资源的安全性和访问控制中起着关键作用。
valid users
项的作用valid users
项,管理员可以明确指定哪些用户或用户组具有访问特定共享资源的权限。这有助于防止未经授权的用户访问敏感信息。valid users
项通常位于配置文件的共享资源定义部分(即[sharename]
部分),并且后面跟着一个或多个用户名或用户组名,这些用户名或用户组名之间用空格或逗号分隔。
[ShareName]
path = /path/to/share
browsable = yes
writable = yes
valid users = user1,user2,@group1
...
在上面的示例中,ShareName
是共享资源的名称,/path/to/share
是共享资源在服务器上的路径。valid users
项指定了用户user1
、user2
以及用户组@group1
的成员具有访问该共享资源的权限。
valid users
项中指定的用户或用户组必须在Samba服务器上已存在。这意味着在配置之前,需要先创建相应的用户和用户组。valid users
项中指定的用户可以是系统用户,但通常建议为Samba服务创建专门的用户,这些用户不需要具有登录系统的权限。这可以通过smbpasswd
命令或Samba的配置管理工具来完成。valid users
项是确保Samba共享资源安全性的重要手段之一。管理员应该根据实际需求仔细配置该项,以确保只有经过授权的用户才能访问共享资源。/etc/samba/smb.conf
文件后,需要重启Samba服务或重新加载配置文件以使更改生效。这通常可以通过系统服务管理工具(如systemctl
、service
等)来完成。valid users
项在Samba的配置文件/etc/samba/smb.conf
中扮演着至关重要的角色,它用于指定哪些用户或用户组被允许访问特定的共享资源。正确配置valid users
项是确保Samba共享资源安全性和访问控制策略的关键步骤之一。
write list
项在Samba的配置文件/etc/samba/smb.conf
中,write list
项是一个用于指定哪些用户或用户组具有对共享资源写入权限的配置项。这个配置项在控制共享资源的访问权限方面起着关键作用,特别是当需要限制只有特定用户才能修改共享内容时。
write list
项的作用write list
项,管理员可以明确指定哪些用户或用户组具有对共享资源的写入(即修改、删除、创建文件等)权限。这有助于保护共享资源免受未经授权的修改。write list
项通常位于配置文件的共享资源定义部分(即[sharename]
部分),并且后面跟着一个或多个用户名或用户组名,这些用户名或用户组名之间用空格或逗号分隔。
[ShareName]
path = /path/to/share
browsable = yes
writable = yes
write list = user1,user2,@group1
...
在上面的示例中,ShareName
是共享资源的名称,/path/to/share
是共享资源在服务器上的路径。write list
项指定了用户user1
、user2
以及用户组@group1
的成员具有对该共享资源的写入权限。
write list
项中指定的用户或用户组必须在Samba服务器上已存在。这意味着在配置之前,需要先创建相应的用户和用户组。writable
选项的关系:虽然write list
项用于控制写入权限,但共享资源本身也需要被设置为可写(即writable = yes
)。如果共享资源被设置为只读(writable = no
),则即使用户在write list
中,也无法对共享资源进行写入操作。write list
项是确保Samba共享资源安全性的重要手段之一。管理员应该根据实际需求仔细配置该项,以确保只有经过授权的用户才能修改共享资源。/etc/samba/smb.conf
文件后,需要重启Samba服务或重新加载配置文件以使更改生效。这通常可以通过系统服务管理工具(如systemctl
、service
等)来完成。write list
项在Samba的配置文件/etc/samba/smb.conf
中用于指定哪些用户或用户组具有对共享资源的写入权限。正确配置write list
项是确保Samba共享资源安全性和访问控制策略的关键步骤之一。
read list
项在Samba的配置文件/etc/samba/smb.conf
中,read list
项用于指定哪些用户或用户组具有对共享资源的读取权限。然而,需要注意的是,并非所有版本的Samba配置文件都直接包含read list
项作为一个标准的配置项。在更常见的配置中,通常会使用valid users
(允许访问的用户列表)和writable
(是否可写)等参数来控制访问权限,而read list
可能不是直接可用的选项。
不过,从概念上讲,read list
如果存在于Samba配置中,其作用将与write list
相对应,但仅限于控制读取权限。然而,在实际应用中,由于Samba配置文件的灵活性和版本差异,管理员可能会通过组合使用不同的配置项来达到类似read list
的效果。
以下是一些可能用于实现类似read list
功能的配置思路:
使用valid users
和writable
组合:
valid users
指定允许访问共享资源的用户或用户组。writable
设置为no
(如果希望限制写入权限),同时允许所有在valid users
中的用户读取共享资源。read list
,但效果上达到了只允许特定用户读取共享资源的目的。自定义脚本或程序:
read list
的功能,通过查询数据库、LDAP服务器或其他认证服务来确定用户的读取权限。利用Samba的ACL(访问控制列表)支持:
setfacl
)来管理ACLs。查阅Samba官方文档和社区资源:
综上所述,虽然/etc/samba/smb.conf
配置文件中可能不直接包含read list
项,但管理员可以通过其他方法来实现类似的功能。重要的是要理解Samba的权限控制机制,并根据实际需求灵活配置。
@
开头在Samba的配置文件/etc/samba/smb.conf
中,用户组名前面的@
符号确实用于明确指定后面跟随的是一个Unix/Linux系统上的组名(group name),而不是一个用户名(user name)。这种表示方法允许Samba服务器根据Unix/Linux系统的组信息来控制对共享资源的访问。
当你在配置文件的某个参数中指定用户或用户组时,如果不使用@
符号,Samba会将其视为用户名。而加上@
符号后,Samba就会知道这是一个组名,并会检查该组是否存在于Unix/Linux系统的/etc/group
文件中,以及当前用户是否属于该组。
以下是一个使用@
符号指定用户组的例子:
[shared]
path = /srv/samba/shared
browsable = yes
writable = yes
valid users = @salesgroup, @marketing
admin users = administrator
在这个例子中,valid users = @salesgroup, @marketing
指定了只有salesgroup
和marketing
这两个组中的用户才能访问名为shared
的共享资源。而admin users = administrator
则指定了administrator
用户具有对该共享资源的额外管理权限(这取决于其他配置,但通常意味着该用户可以进行一些普通用户无法进行的操作)。
需要注意的是,Samba服务器需要能够读取/etc/group
文件(以及/etc/passwd
文件,用于验证用户名)来获取Unix/Linux系统的用户和组信息。此外,如果你的系统使用了其他机制来管理用户和组(如LDAP、Active Directory等),你可能需要配置Samba以使用这些机制进行身份验证和授权。
最后,记得在修改/etc/samba/smb.conf
文件后,需要重启Samba服务或重新加载配置文件以使更改生效。这通常可以通过运行sudo systemctl restart smbd nmbd
(在基于systemd的系统中)或相应的命令来完成。
Samba的配置文件/etc/samba/smb.conf
中使用了几个特殊符号来指示不同的配置和格式要求。以下是这些特殊符号的详细说明:
方括号[]
:
global
、homes
、printers
)被定义在方括号内。[global]
部分包含了全局配置选项,这些选项对Samba服务器上的所有共享都有效,除非在特定共享部分中被覆盖。等号=
:
workgroup = MYGROUP
中,workgroup
是配置项的名称,MYGROUP
是对应的值。分号;
或井号#
:
续行符\
:
\
,然后在下一行继续输入该值。变量替换符号%
:
%
符号开头,后跟变量名。%S
表示当前服务名,%P
表示当前服务的根目录等。这些变量可以在配置文件的路径、用户名等配置项中使用,以实现更灵活的配置。空格和换行符:
\
的使用中,换行符也起到了连接多行配置值的作用。综上所述,/etc/samba/smb.conf
配置文件中的特殊符号主要包括方括号[]
、等号=
、分号;
或井号#
、续行符\
、变量替换符号%
以及空格和换行符等。这些符号共同构成了Samba配置文件的语法结构,使得配置过程既灵活又强大。
CentOS6.0从vault源yum install的samba的配置文件/etc/samba/smb.conf 原版 , 用smbd -V
可看到版本是 3.5.4-68.el6_0.2
samba的版本 Version 3.5.4-68.el6_0.2
# 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 # # For a step to step guide on installing, configuring and using samba, # read the Samba-HOWTO-Collection. This may be obtained from: # http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf # # Many working examples of smb.conf files can be found in the # Samba-Guide which is generated daily and can be downloaded from: # http://www.samba.org/samba/docs/Samba-Guide.pdf # # 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 made any basic syntactic errors. # #--------------- # SELINUX NOTES: # # If you want to use the useradd/groupadd family of binaries please run: # setsebool -P samba_domain_controller on # # If you want to share home directories via samba please run: # setsebool -P samba_enable_home_dirs on # # If you create a new directory you want to share you should mark it as # "samba-share_t" so that selinux will let you write into it. # Make sure not to do that on system directories as they may already have # been marked with othe SELinux labels. # # Use ls -ldZ /path to see which context a directory has # # Set labels only on directories you created! # To set a label use the following: chcon -t samba_share_t /path # # If you need to share a system created directory you can use one of the # following (read-only/read-write): # setsebool -P samba_export_all_ro on # or # setsebool -P samba_export_all_rw on # # If you want to run scripts (preexec/root prexec/print command/...) please # put them into the /var/lib/samba/scripts directory so that smbd will be # allowed to run them. # Make sure you COPY them and not MOVE them so that the right SELinux context # is applied, to check all is ok use restorecon -R -v /var/lib/samba/scripts # #-------------- # #======================= Global Settings ===================================== [global] # ----------------------- Netwrok Related Options ------------------------- # # workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH # # server string is the equivalent of the NT Description field # # netbios name can be used to specify a server name not tied to the hostname # # Interfaces lets you configure Samba to use multiple interfaces # If you have multiple network interfaces then you can list the ones # you want to listen on (never omit localhost) # # Hosts Allow/Hosts Deny lets you restrict who can connect, and you can # specifiy it as a per share option as well # workgroup = MYGROUP server string = Samba Server Version %v ; netbios name = MYSERVER ; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24 ; hosts allow = 127. 192.168.12. 192.168.13. # --------------------------- Logging Options ----------------------------- # # Log File let you specify where to put logs and how to split them up. # # Max Log Size let you specify the max size log files should reach # logs split per machine log file = /var/log/samba/log.%m # max 50KB per log file, then rotate max log size = 50 # ----------------------- Standalone Server Options ------------------------ # # Scurity can be set to user, share(deprecated) or server(deprecated) # # Backend to store user information in. New installations should # use either tdbsam or ldapsam. smbpasswd is available for backwards # compatibility. tdbsam requires no further configuration. security = user passdb backend = tdbsam # ----------------------- Domain Members Options ------------------------ # # Security must be set to domain or ads # # Use the realm option only with security = ads # Specifies the Active Directory realm the host is part of # # Backend to store user information in. New installations should # use either tdbsam or ldapsam. smbpasswd is available for backwards # compatibility. tdbsam requires no further configuration. # # Use password server option only with security = server or if you can't # use the DNS to locate Domain Controllers # The argument list may include: # password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name] # or to auto-locate the domain controller/s # password server = * ; security = domain ; passdb backend = tdbsam ; realm = MY_REALM ; password server = <NT-Server-Name> # ----------------------- Domain Controller Options ------------------------ # # Security must be set to user for domain controllers # # Backend to store user information in. New installations should # use either tdbsam or ldapsam. smbpasswd is available for backwards # compatibility. tdbsam requires no further configuration. # # Domain Master specifies Samba to be the Domain Master Browser. This # allows Samba to collate browse lists between subnets. Don't use this # if you already have a Windows NT domain controller doing this job # # Domain Logons let Samba be a domain logon server for Windows workstations. # # Logon Scrpit let yuou specify a script to be run at login time on the client # You need to provide it in a share called NETLOGON # # Logon Path let you specify where user profiles are stored (UNC path) # # Various scripts can be used on a domain controller or stand-alone # machine to add or delete corresponding unix accounts # ; security = user ; passdb backend = tdbsam ; domain master = yes ; domain logons = yes # the login script name depends on the machine name ; logon script = %m.bat # the login script name depends on the unix user used ; logon script = %u.bat ; logon path = \\%L\Profiles\%u # disables profiles support by specifing an empty path ; logon path = ; add user script = /usr/sbin/useradd "%u" -n -g users ; add group script = /usr/sbin/groupadd "%g" ; add machine script = /usr/sbin/useradd -n -c "Workstation (%u)" -M -d /nohome -s /bin/false "%u" ; delete user script = /usr/sbin/userdel "%u" ; delete user from group script = /usr/sbin/userdel "%u" "%g" ; delete group script = /usr/sbin/groupdel "%g" # ----------------------- Browser Control Options ---------------------------- # # set local master to no if you don't want Samba to become a master # browser on your network. Otherwise the normal election rules apply # # OS Level determines the precedence of this server in master browser # elections. The default value should be reasonable # # Preferred Master causes Samba to force a local browser election on startup # and gives it a slightly higher chance of winning the election ; local master = no ; os level = 33 ; preferred master = yes #----------------------------- Name Resolution ------------------------------- # Windows Internet Name Serving Support Section: # Note: Samba can be either a WINS Server, or a WINS Client, but NOT both # # - WINS Support: Tells the NMBD component of Samba to enable it's WINS Server # # - WINS Server: Tells the NMBD components of Samba to be a WINS Client # # - WINS Proxy: Tells Samba to answer name resolution queries on # behalf of a non WINS capable client, for this to work there must be # at least one WINS Server on the network. The default is NO. # # DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names # via DNS nslookups. ; wins support = yes ; wins server = w.x.y.z ; wins proxy = yes ; dns proxy = yes # --------------------------- Printing Options ----------------------------- # # Load Printers let you load automatically the list of printers rather # than setting them up individually # # Cups Options let you pass the cups libs custom options, setting it to raw # for example will let you use drivers on your Windows clients # # Printcap Name let you specify an alternative printcap file # # You can choose a non default printing system using the Printing option load printers = yes cups options = raw ; printcap name = /etc/printcap #obtain list of printers automatically on SystemV ; printcap name = lpstat ; printing = cups # --------------------------- Filesystem Options --------------------------- # # The following options can be uncommented if the filesystem supports # Extended Attributes and they are enabled (usually by the mount option # user_xattr). Thess options will let the admin store the DOS attributes # in an EA and make samba not mess with the permission bits. # # Note: these options can also be set just per share, setting them in global # makes them the default for all shares ; map archive = no ; map hidden = no ; map read only = no ; map system = no ; store dos attributes = yes #============================ Share Definitions ============================== [homes] comment = Home Directories browseable = no writable = yes ; valid users = %S ; valid users = MYDOMAIN\%S [printers] comment = All Printers path = /var/spool/samba browseable = no guest ok = no writable = no printable = yes # Un-comment the following and create the netlogon directory for Domain Logons ; [netlogon] ; comment = Network Logon Service ; path = /var/lib/samba/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] ; path = /var/lib/samba/profiles ; browseable = no ; guest ok = yes # A publicly accessible directory, but read only, except for people in # the "staff" group ; [public] ; comment = Public Stuff ; path = /home/samba ; public = yes ; writable = yes ; printable = no ; write list = +staff
CentOS7.0从vault源yum install的samba的配置文件/etc/samba/smb.conf 原版 , 用smbd -V
可看到版本是4.1.1
# This is the main Samba configuration file. For detailed information about the # options listed here, refer to the smb.conf(5) manual page. Samba has a huge # number of configurable options, most of which are not shown in this example. # # The Official Samba 3.2.x HOWTO and Reference Guide contains step-by-step # guides for installing, configuring, and using Samba: # http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf # # The Samba-3 by Example guide has working examples for smb.conf. This guide is # generated daily: http://www.samba.org/samba/docs/Samba-Guide.pdf # # In this file, lines starting with a semicolon (;) or a hash (#) are # comments and are ignored. This file uses hashes to denote commentary and # semicolons for parts of the file you may wish to configure. # # Note: Run the "testparm" command after modifying this file to check for basic # syntax errors. # #--------------- # Security-Enhanced Linux (SELinux) Notes: # # Turn the samba_domain_controller Boolean on to allow Samba to use the useradd # and groupadd family of binaries. Run the following command as the root user to # turn this Boolean on: # setsebool -P samba_domain_controller on # # Turn the samba_enable_home_dirs Boolean on if you want to share home # directories via Samba. Run the following command as the root user to turn this # Boolean on: # setsebool -P samba_enable_home_dirs on # # If you create a new directory, such as a new top-level directory, label it # with samba_share_t so that SELinux allows Samba to read and write to it. Do # not label system directories, such as /etc/ and /home/, with samba_share_t, as # such directories should already have an SELinux label. # # Run the "ls -ldZ /path/to/directory" command to view the current SELinux # label for a given directory. # # Set SELinux labels only on files and directories you have created. Use the # chcon command to temporarily change a label: # chcon -t samba_share_t /path/to/directory # # Changes made via chcon are lost when the file system is relabeled or commands # such as restorecon are run. # # Use the samba_export_all_ro or samba_export_all_rw Boolean to share system # directories. To share such directories and only allow read-only permissions: # setsebool -P samba_export_all_ro on # To share such directories and allow read and write permissions: # setsebool -P samba_export_all_rw on # # To run scripts (preexec/root prexec/print command/...), copy them to the # /var/lib/samba/scripts/ directory so that SELinux will allow smbd to run them. # Note that if you move the scripts to /var/lib/samba/scripts/, they retain # their existing SELinux labels, which may be labels that SELinux does not allow # smbd to run. Copying the scripts will result in the correct SELinux labels. # Run the "restorecon -R -v /var/lib/samba/scripts" command as the root user to # apply the correct SELinux labels to these files. # #-------------- # #======================= Global Settings ===================================== [global] # ----------------------- Network-Related Options ------------------------- # # workgroup = the Windows NT domain name or workgroup name, for example, MYGROUP. # # server string = the equivalent of the Windows NT Description field. # # netbios name = used to specify a server name that is not tied to the hostname. # # interfaces = used to configure Samba to listen on multiple network interfaces. # If you have multiple interfaces, you can use the "interfaces =" option to # configure which of those interfaces Samba listens on. Never omit the localhost # interface (lo). # # hosts allow = the hosts allowed to connect. This option can also be used on a # per-share basis. # # hosts deny = the hosts not allowed to connect. This option can also be used on # a per-share basis. # # max protocol = used to define the supported protocol. The default is NT1. You # can set it to SMB2 if you want experimental SMB2 support. # workgroup = MYGROUP server string = Samba Server Version %v ; netbios name = MYSERVER ; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24 ; hosts allow = 127. 192.168.12. 192.168.13. ; max protocol = SMB2 # --------------------------- Logging Options ----------------------------- # # log file = specify where log files are written to and how they are split. # # max log size = specify the maximum size log files are allowed to reach. Log # files are rotated when they reach the size specified with "max log size". # # log files split per-machine: log file = /var/log/samba/log.%m # maximum size of 50KB per log file, then rotate: max log size = 50 # ----------------------- Standalone Server Options ------------------------ # # security = the mode Samba runs in. This can be set to user, share # (deprecated), or server (deprecated). # # passdb backend = the backend used to store user information in. New # installations should use either tdbsam or ldapsam. No additional configuration # is required for tdbsam. The "smbpasswd" utility is available for backwards # compatibility. # security = user passdb backend = tdbsam # ----------------------- Domain Members Options ------------------------ # # security = must be set to domain or ads. # # passdb backend = the backend used to store user information in. New # installations should use either tdbsam or ldapsam. No additional configuration # is required for tdbsam. The "smbpasswd" utility is available for backwards # compatibility. # # realm = only use the realm option when the "security = ads" option is set. # The realm option specifies the Active Directory realm the host is a part of. # # password server = only use this option when the "security = server" # option is set, or if you cannot use DNS to locate a Domain Controller. The # argument list can include My_PDC_Name, [My_BDC_Name], and [My_Next_BDC_Name]: # # password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name] # # Use "password server = *" to automatically locate Domain Controllers. ; security = domain ; passdb backend = tdbsam ; realm = MY_REALM ; password server = <NT-Server-Name> # ----------------------- Domain Controller Options ------------------------ # # security = must be set to user for domain controllers. # # passdb backend = the backend used to store user information in. New # installations should use either tdbsam or ldapsam. No additional configuration # is required for tdbsam. The "smbpasswd" utility is available for backwards # compatibility. # # domain master = specifies Samba to be the Domain Master Browser, allowing # Samba to collate browse lists between subnets. Do not use the "domain master" # option if you already have a Windows NT domain controller performing this task. # # domain logons = allows Samba to provide a network logon service for Windows # workstations. # # logon script = specifies a script to run at login time on the client. These # scripts must be provided in a share named NETLOGON. # # logon path = specifies (with a UNC path) where user profiles are stored. # # ; security = user ; passdb backend = tdbsam ; domain master = yes ; domain logons = yes # the following login script name is determined by the machine name # (%m): ; logon script = %m.bat # the following login script name is determined by the UNIX user used: ; logon script = %u.bat ; logon path = \\%L\Profiles\%u # use an empty path to disable profile support: ; logon path = # various scripts can be used on a domain controller or a stand-alone # machine to add or delete corresponding UNIX accounts: ; add user script = /usr/sbin/useradd "%u" -n -g users ; add group script = /usr/sbin/groupadd "%g" ; add machine script = /usr/sbin/useradd -n -c "Workstation (%u)" -M -d /nohome -s /bin/false "%u" ; delete user script = /usr/sbin/userdel "%u" ; delete user from group script = /usr/sbin/userdel "%u" "%g" ; delete group script = /usr/sbin/groupdel "%g" # ----------------------- Browser Control Options ---------------------------- # # local master = when set to no, Samba does not become the master browser on # your network. When set to yes, normal election rules apply. # # os level = determines the precedence the server has in master browser # elections. The default value should be reasonable. # # preferred master = when set to yes, Samba forces a local browser election at # start up (and gives itself a slightly higher chance of winning the election). # ; local master = no ; os level = 33 ; preferred master = yes #----------------------------- Name Resolution ------------------------------- # # This section details the support for the Windows Internet Name Service (WINS). # # Note: Samba can be either a WINS server or a WINS client, but not both. # # wins support = when set to yes, the NMBD component of Samba enables its WINS # server. # # wins server = tells the NMBD component of Samba to be a WINS client. # # wins proxy = when set to yes, Samba answers name resolution queries on behalf # of a non WINS capable client. For this to work, there must be at least one # WINS server on the network. The default is no. # # dns proxy = when set to yes, Samba attempts to resolve NetBIOS names via DNS # nslookups. ; wins support = yes ; wins server = w.x.y.z ; wins proxy = yes ; dns proxy = yes # --------------------------- Printing Options ----------------------------- # # The options in this section allow you to configure a non-default printing # system. # # load printers = when set you yes, the list of printers is automatically # loaded, rather than setting them up individually. # # cups options = allows you to pass options to the CUPS library. Setting this # option to raw, for example, allows you to use drivers on your Windows clients. # # printcap name = used to specify an alternative printcap file. # load printers = yes cups options = raw ; printcap name = /etc/printcap # obtain a list of printers automatically on UNIX System V systems: ; printcap name = lpstat ; printing = cups # --------------------------- File System Options --------------------------- # # The options in this section can be un-commented if the file system supports # extended attributes, and those attributes are enabled (usually via the # "user_xattr" mount option). These options allow the administrator to specify # that DOS attributes are stored in extended attributes and also make sure that # Samba does not change the permission bits. # # Note: These options can be used on a per-share basis. Setting them globally # (in the [global] section) makes them the default for all shares. ; map archive = no ; map hidden = no ; map read only = no ; map system = no ; store dos attributes = yes #============================ Share Definitions ============================== [homes] comment = Home Directories browseable = no writable = yes ; valid users = %S ; valid users = MYDOMAIN\%S [printers] comment = All Printers path = /var/spool/samba browseable = no guest ok = no writable = no printable = yes # Un-comment the following and create the netlogon directory for Domain Logons: ; [netlogon] ; comment = Network Logon Service ; path = /var/lib/samba/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] ; path = /var/lib/samba/profiles ; browseable = no ; guest ok = yes # A publicly accessible directory that is read only, except for users in the # "staff" group (which have write permissions): ; [public] ; comment = Public Stuff ; path = /home/samba ; public = yes ; writable = yes ; printable = no ; write list = +staff
用 smbd -V
或 nmbd -V
可以查看版本
[root@48vm-c70mEn ~]# smbd -V
Version 4.1.1
[root@48vm-c70mEn ~]# nmbd -V
Version 4.1.1
CentOS7.9从vault源yum install的samba的配置文件/etc/samba/smb.conf 原版 , 用smbd -V
可看到版本是 Version 4.10.16
和 CentOS7.0 从vault获得的版本不一样
[global] workgroup = SAMBA security = user passdb backend = tdbsam printing = cups printcap name = cups load printers = yes cups options = raw [homes] comment = Home Directories valid users = %S, %D%w%S browseable = No read only = No inherit acls = Yes [printers] comment = All Printers path = /var/tmp printable = Yes create mask = 0600 browseable = No [print$] comment = Printer Drivers path = /var/lib/samba/drivers write list = @printadmin root force group = @printadmin create mask = 0664 directory mask = 0775
版本是 : Version 4.20.2
# See smb.conf.example for a more detailed config file or # read the smb.conf manpage. # Run 'testparm' to verify the config is correct after # you modified it. # # Note: # SMB1 is disabled by default. This means clients without support for SMB2 or # SMB3 are no longer able to connect to smbd (by default). [global] workgroup = SAMBA security = user passdb backend = tdbsam printing = cups printcap name = cups load printers = yes cups options = raw # Install samba-usershares package for support include = /etc/samba/usershares.conf [homes] comment = Home Directories valid users = %S, %D%w%S browseable = No read only = No inherit acls = Yes [printers] comment = All Printers path = /var/tmp printable = Yes create mask = 0600 browseable = No [print$] comment = Printer Drivers path = /var/lib/samba/drivers write list = @printadmin root force group = @printadmin create mask = 0664 directory mask = 0775
版本是 : Version 4.19.5-Ubuntu
# # Sample configuration file for the Samba suite for Debian GNU/Linux. # # # 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 most of which # are not shown in this example # # Some options that are often worth tuning have been included as # commented-out examples in this file. # - When such options are commented with ";", the proposed setting # differs from the default Samba behaviour # - When commented with "#", the proposed setting is the default # behaviour of Samba but the option is considered important # enough to be mentioned here # # NOTE: Whenever you modify this file you should run the command # "testparm" to check that you have not made any basic syntactic # errors. #======================= Global Settings ======================= [global] ## Browsing/Identification ### # Change this to the workgroup/NT-domain name your Samba server will part of workgroup = WORKGROUP # server string is the equivalent of the NT Description field server string = %h server (Samba, Ubuntu) #### Networking #### # The specific set of interfaces / networks to bind to # This can be either the interface name or an IP address/netmask; # interface names are normally preferred ; interfaces = 127.0.0.0/8 eth0 # Only bind to the named interfaces and/or networks; you must use the # 'interfaces' option above to use this. # It is recommended that you enable this feature if your Samba machine is # not protected by a firewall or is a firewall itself. However, this # option cannot handle dynamic or non-broadcast interfaces correctly. ; bind interfaces only = yes #### Debugging/Accounting #### # This tells Samba to use a separate log file for each machine # that connects log file = /var/log/samba/log.%m # Cap the size of the individual log files (in KiB). max log size = 1000 # We want Samba to only log to /var/log/samba/log.{smbd,nmbd}. # Append syslog@1 if you want important messages to be sent to syslog too. logging = file # Do something sensible when Samba crashes: mail the admin a backtrace panic action = /usr/share/samba/panic-action %d ####### Authentication ####### # Server role. Defines in which mode Samba will operate. Possible # values are "standalone server", "member server", "classic primary # domain controller", "classic backup domain controller", "active # directory domain controller". # # Most people will want "standalone server" or "member server". # Running as "active directory domain controller" will require first # running "samba-tool domain provision" to wipe databases and create a # new domain. server role = standalone server obey pam restrictions = yes # This boolean parameter controls whether Samba attempts to sync the Unix # password with the SMB password when the encrypted SMB password in the # passdb is changed. unix password sync = yes # For Unix password sync to work on a Debian GNU/Linux system, the following # parameters must be set (thanks to Ian Kahan <<kahan@informatik.tu-muenchen.de> for # sending the correct chat script for the passwd program in Debian Sarge). passwd program = /usr/bin/passwd %u passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* . # This boolean controls whether PAM will be used for password changes # when requested by an SMB client instead of the program listed in # 'passwd program'. The default is 'no'. pam password change = yes # This option controls how unsuccessful authentication attempts are mapped # to anonymous connections map to guest = bad user ########## Domains ########### # # The following settings only takes effect if 'server role = classic # primary domain controller', 'server role = classic backup domain controller' # or 'domain logons' is set # # It specifies the location of the user's # profile directory from the client point of view) The following # required a [profiles] share to be setup on the samba server (see # below) ; logon path = \\%N\profiles\%U # Another common choice is storing the profile in the user's home directory # (this is Samba's default) # logon path = \\%N\%U\profile # The following setting only takes effect if 'domain logons' is set # It specifies the location of a user's home directory (from the client # point of view) ; logon drive = H: # logon home = \\%N\%U # The following setting only takes effect if 'domain logons' is set # It specifies the script to run during logon. The script must be stored # in the [netlogon] share # NOTE: Must be store in 'DOS' file format convention ; logon script = logon.cmd # This allows Unix users to be created on the domain controller via the SAMR # RPC pipe. The example command creates a user account with a disabled Unix # password; please adapt to your needs ; add user script = /usr/sbin/useradd --create-home %u # This allows machine accounts to be created on the domain controller via the # SAMR RPC pipe. # The following assumes a "machines" group exists on the system ; add machine script = /usr/sbin/useradd -g machines -c "%u machine account" -d /var/lib/samba -s /bin/false %u # This allows Unix groups to be created on the domain controller via the SAMR # RPC pipe. ; add group script = /usr/sbin/addgroup --force-badname %g ############ Misc ############ # Using the following line enables you to customise your configuration # on a per machine basis. The %m gets replaced with the netbios name # of the machine that is connecting ; include = /home/samba/etc/smb.conf.%m # Some defaults for winbind (make sure you're not using the ranges # for something else.) ; idmap config * : backend = tdb ; idmap config * : range = 3000-7999 ; idmap config YOURDOMAINHERE : backend = tdb ; idmap config YOURDOMAINHERE : range = 100000-999999 ; template shell = /bin/bash # Setup usershare options to enable non-root users to share folders # with the net usershare command. # Maximum number of usershare. 0 means that usershare is disabled. # usershare max shares = 100 # Allow users who've been granted usershare privileges to create # public shares, not just authenticated ones usershare allow guests = yes #======================= Share Definitions ======================= # Un-comment the following (and tweak the other settings below to suit) # to enable the default home directory shares. This will share each # user's home directory as \\server\username ;[homes] ; comment = Home Directories ; browseable = no # By default, the home directories are exported read-only. Change the # next parameter to 'no' if you want to be able to write to them. ; read only = yes # File creation mask is set to 0700 for security reasons. If you want to # create files with group=rw permissions, set next parameter to 0775. ; create mask = 0700 # Directory creation mask is set to 0700 for security reasons. If you want to # create dirs. with group=rw permissions, set next parameter to 0775. ; directory mask = 0700 # By default, \\server\username shares can be connected to by anyone # with access to the samba server. # Un-comment the following parameter to make sure that only "username" # can connect to \\server\username # This might need tweaking when using external authentication schemes ; valid users = %S # Un-comment the following and create the netlogon directory for Domain Logons # (you need to configure Samba to act as a domain controller too.) ;[netlogon] ; comment = Network Logon Service ; path = /home/samba/netlogon ; guest ok = yes ; read only = yes # Un-comment the following and create the profiles directory to store # users profiles (see the "logon path" option above) # (you need to configure Samba to act as a domain controller too.) # The path below should be writable by all users so that their # profile directory may be created the first time they log on ;[profiles] ; comment = Users profiles ; path = /home/samba/profiles ; guest ok = no ; browseable = no ; create mask = 0600 ; directory mask = 0700 [printers] comment = All Printers browseable = no path = /var/tmp printable = yes guest ok = no read only = yes create mask = 0700 # Windows clients look for this share name as a source of downloadable # printer drivers [print$] comment = Printer Drivers path = /var/lib/samba/printers browseable = yes read only = yes guest ok = no # Uncomment to allow remote administration of Windows print drivers. # You may need to replace 'lpadmin' with the name of the group your # admin users are members of. # Please note that you also need to set appropriate Unix permissions # to the drivers directory for these users to have write rights in it ; write list = root, @lpadmin
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。