16.7 Samba 服务器
Samba 是对 SMB/CIFS(Server Message Block,服务器消息块)协议的再实现。CIFS(Common Internet File System,通用 Internet 文件系统)是 SMB 的衍生协议。
Samba 也是“桑巴舞”的葡萄牙语/英语对应的单词。有热情奔放的含义。
samba 须开放防火墙的 tcp/139、445 端口;udp/137、138 端口。
安装 samba
使用 pkg 安装:
# pkg install samba420或使用 Ports 安装:
# cd /usr/ports/net/samba420/
# make install clean查看安装后说明
# pkg info -D samba420
samba420-4.20.7_4:
On install: # 安装提示:
How to start: http://wiki.samba.org/index.php/Samba4/HOWTO
如何启动:参见官方指南
* Your configuration is: /usr/local/etc/smb4.conf
* 你的配置文件路径是:/usr/local/etc/smb4.conf
* All the relevant databases are under: /var/db/samba4
* 所有相关数据库位于:/var/db/samba4
* All the logs are under: /var/log/samba4
* 所有日志位于:/var/log/samba4
* Provisioning script is: /usr/local/bin/samba-tool
* # 初始化脚本是:/usr/local/bin/samba-tool
For the working DNS updates you will need to either build dns/bind9*
# 若需正常使用 DNS 更新功能,你需要:
with the enabled GSSAPI(GSSAPI_MIT5 is recommended) or install
# 要么构建启用了 GSSAPI(推荐 GSSAPI_MIT5)的 dns/bind9*,
dns/samba-nsupdate package, which is preconfigured with such a support.
# 要么安装 dns/samba-nsupdate 包,它已预配置了所需支持。
You will need to specify location of the 'nsupdate' command in the
smb4.conf file:
# 你需要在 smb4.conf 中指定 nsupdate 命令的位置:
nsupdate command = /usr/local/bin/samba-nsupdate -g # 示例配置
For additional documentation check: https://wiki.samba.org/index.php/User_Documentation
# 更多文档请查阅:
Port related bug reports can go to the https://gitlab.com/samba-freebsd/ports/-/issues or
# 和 FreeBSD port 相关的问题请提交到:
to the FreeBSD Bugzilla https://bugs.freebsd.org/
# 所有 Samba 本身相关的问题请提交到:
All Samba related bug reports should go to the: https://bugzilla.samba.org/ 配置 samba
配置服务
创建
/usr/local/etc/smb4.conf,添加如下内容并保存
注释说明:
[global]:全局配置段,适用于所有共享项。min protocol = SMB2:将最小支持协议限制为 SMB2,以方便高版本 Windows 访问[root]:定义一个名为root的共享。comment = root's stuff:该共享的描述信息,Windows 浏览器中可见。path = /root:共享的实际路径是/root,不推荐 在实际环境中共享该目录。public = no:不允许匿名访问(等同于guest ok = no)。browseable = yes:可在网络邻居中浏览共享。writable = yes:允许客户端对该目录进行写入。printable = no:不是打印机共享。create mask = 0755:新建文件默认权限为 755,所有者读写,组和其他用户只读。
创建 samba root 用户,并配置密码:
启动服务
查看 samba 状态:
在 Windows 下使用如下命令访问共享文件夹(以实际 IP 为准,照抄不管用!):
技巧
在 Windows 下访问共享文件夹说明:按下 Windows 键 + R(小写 r 也可以)打开“运行”对话框。在对话框中输入以下命令(以实际 IP 地址和共享文件夹名替换示例中的内容):

输入刚才创建的用户名 root,以及密码:

连接成功:

将 Samba 设置为域成员
环境:freebsd 12
配置静态 IP 地址
使用如下命令配置:
配置主机名
在安装系统的时候应该都配置了主机名,你可以在 /etc/rc.conf 查看或编辑设置:
配置 DNS
编辑 /etc/resolv.conf,写入:
修改 /etc/sysctl.conf
/etc/sysctl.conf创建 /etc/krb5.conf
/etc/krb5.conf修改 /etc/nsswitch.conf
/etc/nsswitch.conf创建 /usr/local/etc/smb4.conf
/usr/local/etc/smb4.conf上面“testshare”最后两行内容实际使用权限优化(可选)
将 samba 加入到域
使 samba 启动并设置为开机自启动
测试 Kerberos
测试 Winbind
如果 wbinfo 命令显示报错,请执行命令
创建共享文件夹
如果只允许属主可读可写,属组只允许读,用以下命令设置:
如果只允许属主可读可写,属组和其他均不可读写,用以下命令设置:
故障排除与未竞事宜
Samba 日志位于 /var/log/samba4。
最后更新于
这有帮助吗?