# Samba（软件）

**Samba**是一套自由软件的Unix程序套件，实现了[服务器消息块](https://www.edgepedia.org/zh/server-message-block)（SMB）协议，提供文件、打印和认证服务，使Unix和Linux服务器能够与Windows及其他SMB客户端共享资源。SMB协议的第一个版本也称为通用互联网文件系统（CIFS），Samba两者都支持。<sup>[1](https://www.samba.org/samba/docs/current/man-html/samba.7.html)</sup>该套件在GNU通用公共许可证（GPL）下授权，由Samba团队作为开源项目开发。<sup>[1](https://www.samba.org/samba/docs/current/man-html/samba.7.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 是什么 | 一套使用SMB协议的Unix应用程序，为Windows客户端提供文件、打印和认证服务<sup>[2](https://www.samba.org/samba/docs/using_samba/ch01.html)</sup> |
| 起源 | 由安德鲁·特里奇尔（Andrew Tridgell）于1991年在使用DEC的Pathworks时发起；代码于1992年初首次发布<sup>[3](https://www.samba.org/samba/docs/SambaIntro.html)</sup> |
| 核心守护进程 | `smbd`（文件和打印服务）、`nmbd`（NetBIOS名称服务和浏览）、`winbindd`（将认证和用户数据库集成到Unix中）<sup>[1](https://www.samba.org/samba/docs/current/man-html/samba.7.html)</sup> |
| 网络端口 | smbd监听TCP端口139（基于TCP的NetBIOS上的SMB）和端口445（基于TCP的纯SMB）<sup>[4](https://devel.samba.org/samba/docs/current/man-html/smbd.8.html)</sup> |
| 配置 | 主配置文件`/etc/samba/smb.conf`；共享以节的形式定义；`testparm`检查语法<sup>[5](https://documentation.ubuntu.com/server/how-to/samba/file-server/index.html)</sup> |
| 活动目录 | Samba 4.0（2012年12月11日）是首个自由软件活动目录兼容域控制器<sup>[6](https://www.samba.org/samba/news/releases/4.0.0.html)</sup> |
| 协议支持 | Samba 4.0包含首个自由软件SMB2.1实现以及SMB3的初步实现<sup>[6](https://www.samba.org/samba/news/releases/4.0.0.html)</sup> |
| 许可证 | GNU通用公共许可证（GPL）<sup>[1](https://www.samba.org/samba/docs/current/man-html/samba.7.html)</sup> |

## 它所服务的SMB协议

服务器消息块协议是一种网络文件共享协议，允许应用程序通过TCP/IP或其他传输协议在远程服务器上读取、创建和更新文件。<sup>[7](https://learn.microsoft.com/en-us/windows-server/storage/file-server/file-server-smb-overview)</sup>共享是SMB客户端可以访问的文件、目录或打印机，该协议还涵盖网络打印、文件和记录锁定、更改通知以及机会锁。<sup>[8](https://learn.microsoft.com/windows/desktop/fileio/microsoft-smb-protocol-and-cifs-protocol-overview)</sup>定义协议特定版本的消息包集合称为方言；CIFS是SMB的一种方言。<sup>[8](https://learn.microsoft.com/windows/desktop/fileio/microsoft-smb-protocol-and-cifs-protocol-overview)</sup>当客户端和服务器连接时，它们协商使用双方都支持的最高方言版本。<sup>[7](https://learn.microsoft.com/en-us/windows-server/storage/file-server/file-server-smb-overview)</sup>在Windows中，SMB 3.1.1由[Windows 10](https://www.edgepedia.org/zh/windows-10)版本1607及更高版本的客户端和[Windows Server 2016](https://www.edgepedia.org/zh/windows-server-2016)及更高版本的服务器支持。<sup>[7](https://learn.microsoft.com/en-us/windows-server/storage/file-server/file-server-smb-overview)</sup>

微软通过于1996年向[互联网工程任务组](https://www.edgepedia.org/zh/internet-engineering-task-force)（IETF）提交其SMB定义（即通用互联网文件系统）来推动该协议的开放性。<sup>[2](https://www.samba.org/samba/docs/using_samba/ch01.html)</sup>

## 历史

**起源。** 安德鲁·特里奇尔是一位澳大利亚计算机科学家，后来在[澳大利亚国立大学](https://www.edgepedia.org/zh/australian-national-university)获得博士学位。他于1991年在使用[数字设备公司](https://www.edgepedia.org/zh/digital-equipment-corporation)一套名为Pathworks的软件套件时启动了该项目，该套件用于将DEC VAX计算机连接到其他公司制造的机器。<sup>[2](https://www.samba.org/samba/docs/using_samba/ch01.html)</sup>为了使Unix系统表现为PC文件服务器，他编写了一个数据包嗅探器，对SMB协议进行了逆向工程，并在Unix机器上实现了它，这使他能够在运行NetBIOS应用程序的同时从Unix服务器挂载共享文件系统。<sup>[3](https://www.samba.org/samba/docs/SambaIntro.html)</sup>他于1992年初发布了代码，然后将项目搁置，直到将近两年后，他用自己编写的服务器代码将妻子的Windows PC与他的Linux系统连接起来，结果成功了。<sup>[3](https://www.samba.org/samba/docs/SambaIntro.html)</sup>

**名称。** 在发现NetBIOS和SMB有文档记录后，特里奇尔恢复了工作，但一家公司联系他，声称对他所选名称拥有商标权。他快速扫描了拼写检查词典，寻找包含字母“smb”的单词，“Samba”就在列表中。<sup>[3](https://www.samba.org/samba/docs/SambaIntro.html)</sup>

**发展。** 从用于DOS Pathworks客户端和Sun服务器之间通信的原型，Samba演变为面向Windows客户端的可靠文件和打印服务器，由30多名国际开发者组成的团队维护，任何时间约有12人活跃，开发工作部分由澳大利亚国立大学赞助。<sup>[2](https://www.samba.org/samba/docs/using_samba/ch01.html)</sup>Samba 2.0带来了新水平的协议完整性和对成为域成员的初步支持。<sup>[9](https://www.samba.org/samba/news/articles/abartlet_thesis.pdf)</sup>该项目的成功甚至在微软内部也受到关注：Samba被列入“万圣节文件”，这是一对泄露给开源社区的微软内部备忘录。<sup>[3](https://www.samba.org/samba/docs/SambaIntro.html)</sup>

## Samba 4.0与活动目录

Samba 4.0于2012年12月11日发布，历经十年工作，是微软活动目录协议的首个兼容自由软件实现。<sup>[6](https://www.samba.org/samba/news/releases/4.0.0.html)</sup>它包含一个LDAP目录服务器、一个Heimdal Kerberos认证服务器、一个安全动态DNS服务器，以及活动目录所需的远程过程调用实现，使其能够作为活动目录兼容域控制器，服务于微软当时支持的所有版本的Windows客户端，包括[Windows 8](https://www.edgepedia.org/zh/windows-8)。<sup>[6](https://www.samba.org/samba/news/releases/4.0.0.html)</sup>它支持组策略、漫游配置文件和Windows管理工具等功能，Samba域控制器可以加入现有的微软活动目录域，反之亦然。<sup>[6](https://www.samba.org/samba/news/releases/4.0.0.html)</sup>该实现是在微软官方协议文档和微软工程师互操作性测试的帮助下构建的。<sup>[6](https://www.samba.org/samba/news/releases/4.0.0.html)</sup>

Samba 4.0还包含微软SMB2.1文件服务协议的首个自由软件实现，建立在Samba 3.6中的SMB2.0服务器之上，以及SMB3的初步实现，后者在后续Samba 4版本中进一步发展。<sup>[6](https://www.samba.org/samba/news/releases/4.0.0.html)</sup>Samba文件服务代码被文件服务器供应商使用，例如IBM的集群横向扩展网络附加存储（SONAS）和其他商业产品。<sup>[6](https://www.samba.org/samba/news/releases/4.0.0.html)</sup>

## 组件

该套件围绕若干守护进程和实用工具组织。<sup>[1](https://www.samba.org/samba/docs/current/man-html/samba.7.html)</sup>

- **smbd**是服务器守护进程，为使用SMB（或CIFS）协议的客户端提供文件共享和打印服务，兼容LanManager协议，能够服务于DOS的MSCLIENT 3.0、Windows for Workgroups、Windows 95/98/ME、[Windows NT](https://www.edgepedia.org/zh/windows-nt)、Windows 2000、OS/2、Macintosh的DAVE以及Linux的smbfs等客户端。<sup>[4](https://devel.samba.org/samba/docs/current/man-html/smbd.8.html)</sup>每个客户端会话获得服务器的一个副本，当客户端的连接关闭时该副本终止。<sup>[4](https://devel.samba.org/samba/docs/current/man-html/smbd.8.html)</sup>
- **nmbd**提供NetBIOS名称服务和浏览支持。<sup>[1](https://www.samba.org/samba/docs/current/man-html/samba.7.html)</sup>
- **winbindd**将认证和用户数据库集成到Unix中，为大多数现代C库中的名称服务切换功能提供服务，通过PAM和`ntlm_auth`为应用程序提供服务，并通过管理与域控制器的连接为Samba本身提供服务。<sup>[1](https://www.samba.org/samba/docs/current/man-html/samba.7.html)</sup><sup> • </sup><sup>[10](https://www.samba.org/samba/samba/docs/man/manpages/winbindd.8.html)</sup>
- 当作为活动目录域控制器运行时，单个`samba`守护进程协调所需的服务，而不是smbd、nmbd和winbindd，使用`samba-tool`实用工具进行管理。<sup>[11](https://www.samba.org/samba/history/samba-4.0.0.html)</sup>

客户端和管理工具包括`smbclient`，一个类似ftp的客户端，用于访问SMB共享；`smbstatus`，报告到smbd的当前连接；`smbpasswd`用于设置密码；`smbcacls`用于在远程SMB服务器上设置ACL；以及`testparm`，一个配置文件语法检查器。<sup>[1](https://www.samba.org/samba/docs/current/man-html/samba.7.html)</sup>

## 配置与部署

在Ubuntu系统上，主配置文件是`/etc/samba/smb.conf`，除`[global]`之外的每一节描述一个共享资源，即共享：被授予访问权限的目录加上所授予访问权限的描述。<sup>[5](https://documentation.ubuntu.com/server/how-to/samba/file-server/index.html)</sup><sup> • </sup><sup>[12](https://manpages.ubuntu.com/manpages/jammy/man5/smb.conf.5.html)</sup>存在三个特殊节：`[global]`、`[homes]`和`[printers]`。<sup>[12](https://manpages.ubuntu.com/manpages/jammy/man5/smb.conf.5.html)</sup>常见的共享参数包括`path`、`browsable`（让Windows客户端在Windows资源管理器中浏览共享）、`guest ok`（允许无密码连接）、`read only`和`create mask`（决定新文件获得的权限）。<sup>[5](https://documentation.ubuntu.com/server/how-to/samba/file-server/index.html)</sup>更改在重启Samba服务后生效，例如Ubuntu上的`smbd.service`和`nmbd.service`。<sup>[5](https://documentation.ubuntu.com/server/how-to/samba/file-server/index.html)</sup>

在[Red Hat Enterprise Linux](https://www.edgepedia.org/zh/red-hat-enterprise-linux)上，Samba可以设置为独立服务器或域成员，管理员使用`testparm`验证配置，使用`firewall-cmd --permanent --add-service=samba`打开所需端口，并使用systemd管理`smb`服务。<sup>[13](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/configuring_and_using_network_file_services/using-samba-as-a-server)</sup>当SELinux以强制模式运行时，必须在共享目录上设置`samba_share_t`上下文。<sup>[13](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/configuring_and_using_network_file_services/using-samba-as-a-server)</sup>

**访问控制。** Samba支持具有POSIX访问控制列表的共享，使用`chmod`等实用工具在本地管理，也支持细粒度的Windows ACL，通过`vfs objects = acl_xattr`等设置启用，并通过计算机管理等Windows工具或`smbcacls`实用工具进行管理。<sup>[13](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/configuring_and_using_network_file_services/using-samba-as-a-server)</sup>在最简单的层面上，smbd处理“共享模式”和“用户模式”两种认证：在共享模式下，为共享目录或打印机分配一个密码，并给予所有被允许使用它的人，Samba文档称这种方案是最简单也最不推荐的。<sup>[3](https://www.samba.org/samba/docs/SambaIntro.html)</sup>

## 安全性

Samba项目按版本发布安全公告和补丁。其安全历史中的例子包括CVE-2019-10197，其中参数和权限的组合可能允许用户逃逸共享路径定义，影响Samba 4.9.0至4.9.12和4.10.7版本；以及CVE-2017-11103，“俄耳甫斯之琴”双向认证验证绕过，影响Samba 4.0.0至4.6.6、4.5.12和4.4.15之间的所有版本。<sup>[14](https://www.samba.org/samba/history/security.html?trk=public_post_comment-text)</sup>smbd手册页指出，运行服务器具有重大的安全影响，并认为smb.conf手册页是安装前必读的。<sup>[4](https://devel.samba.org/samba/docs/current/man-html/smbd.8.html)</sup>

## 平台覆盖

Samba和Windows并非CIFS网络的唯一提供者：OS/2支持SMB文件和打印共享，Macintosh和其他平台存在商业CIFS产品，Samba本身已被移植到非Unix操作系统，包括VMS、AmigaOS和NetWare。<sup>[3](https://www.samba.org/samba/docs/SambaIntro.html)</sup>商业系统供应商，包括硅谷图形公司（Silicon Graphics），已将Samba与其产品捆绑。<sup>[3](https://www.samba.org/samba/docs/SambaIntro.html)</sup>

## References

1. [samba(7) man page, Samba](https://www.samba.org/samba/docs/current/man-html/samba.7.html)
2. [Using Samba, Chapter 1, O'Reilly/Samba.org](https://www.samba.org/samba/docs/using_samba/ch01.html)
3. [Samba: An Introduction, Samba.org](https://www.samba.org/samba/docs/SambaIntro.html)
4. [smbd(8) man page, Samba](https://devel.samba.org/samba/docs/current/man-html/smbd.8.html)
5. [Set up Samba as a file server, Ubuntu Server documentation](https://documentation.ubuntu.com/server/how-to/samba/file-server/index.html)
6. [Samba Team Releases Samba 4.0, Samba.org press release, December 11, 2012](https://www.samba.org/samba/news/releases/4.0.0.html)
7. [What is SMB File Sharing for Windows and Windows Server?, Microsoft Learn](https://learn.microsoft.com/en-us/windows-server/storage/file-server/file-server-smb-overview)
8. [Microsoft SMB Protocol and CIFS Protocol Overview, Microsoft Learn](https://learn.microsoft.com/windows/desktop/fileio/microsoft-smb-protocol-and-cifs-protocol-overview)
9. [Samba 4 - Active Directory (Andrew Bartlett thesis), Samba.org](https://www.samba.org/samba/news/articles/abartlet_thesis.pdf)
10. [winbindd(8) man page, Samba](https://www.samba.org/samba/samba/docs/man/manpages/winbindd.8.html)
11. [Release Notes for Samba 4.0.0, Samba.org](https://www.samba.org/samba/history/samba-4.0.0.html)
12. [smb.conf(5) man page, Ubuntu Manpages](https://manpages.ubuntu.com/manpages/jammy/man5/smb.conf.5.html)
13. [Using Samba as a server, Red Hat Enterprise Linux 10 documentation](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/configuring_and_using_network_file_services/using-samba-as-a-server)
14. [Samba Security Updates and Information, Samba.org](https://www.samba.org/samba/history/security.html?trk=public_post_comment-text)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Networking fundamentals and architecture › Networking fundamentals overview

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/samba-software

English original: https://www.edgepedia.org/samba-software
