NotePublic/Software/Application/Samba/Linux_搭建_Samba_服务器.md

42 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Linux 搭建 Samba 服务器
Samba 主要提供三个服务器工具smbd、nmbd、smbpasswd。smb 是 Samba 的主要启动服务器用于实现共享服务nmbd 是名称服务器,不开启 nmbd 的情况下只能通过 ip 地址来访问 samba 服务器,如果开启了 nmbd 则可以通过 netbios name 来访问 samba 服务smbpasswd 用来设置访问 samba 服务的账户名和密码。
smbd 的运行依赖于 /etc/samba/smb.conf 配置文件,这个是 smbd 的默认配置文件。访问 samba 服务需要账户名和密码,这个通过 smbpasswd 来设置。
## 创建配置文件
在 /etc/samba 下创建 smb.conf 文件,编写内容如下:
```sh
[global]
security = user
guest account = nobody
map to guest = bad password
[NAME]
available = yes
browseable = yes
path = /YOUPATH
public = yes
writable = yes
create mask = 0777
sync always = yes
```
其中 NAME 为共享时虚拟的文件夹名YOUPATH 为共享文件夹的路径。security 可以设置成 share 或 user 等share 方式访问时不需要账户密码。
## 分配账户和密码
在 shell 中输入如下命令为 samba 服务分配账户和密码
smbpasswd -a <user name>
## 开启 Samba 服务
通过 systemctl 开启 samba 服务命令如下:
systemctl enable smb.service
systemctl start smb.service
必要时需要关闭防火墙,或设置防火墙规则。