ubuntu18安装Samba

Table of Contents

安装Samba服务

sudo apt update -y
sudo apt install samba samba-common -y

新建Samba用户

sudo groupadd smb
sudo useradd -s /sbin/nologin -g smb huu

设置Samba用户密码

sudo smbpasswd -a huu

配置Samba

编辑文件sudo vi /etc/samba/smb.conf,添加内容,
[global]
workgroup = WORKGROUP
netbios name = NAS
server string = Samba Server
server string = NAS Samba Server TestServer
security = user
include = /etc/samba/%U.smb.conf
log file = /var/log/samba/%m.log
max log size = 5000
username map = /etc/samba/smbusers
unix charset = UTF-8
dos charset = CP936
display charset = UTF-8
hosts allow = 172.17.0.0/16 127.0.0.1
passdb backend = tdbsam

编辑文件sudo vi /etc/samba/huu.smb.conf,添加内容,
[MOVIE]
comment = MOVIE
path = /mnt/brook
writable = yes
read list = huu
write list = huu
browseable = yes
valid_user = huu
passdb backend = smbpasswd
create mask = 0777
directory mask = 0777

编辑文件sudo vi /etc/samba/smbusers,添加内容,
root = administrator admin huu
nobody = guest pcguest smbguest

启动Samba

sudo systemctl enable smbd
sudo systemctl restart smbd
ps aux | grep smb
sudo netstat -nltp | grep -iE "139|445"

win10如果连接Samba报错“用户名或密码不正确”,参考以下连接更改安全策略解决。

https://www.hesiyang.top/2019/03/05/367/#:~:text=Ubuntu%20Server,%E5%9C%A8%E8%AE%BF%E9%97%AEsamba%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%97%B6%EF%BC%8C%E6%88%91%E7%9A%84%E4%B8%80%E5%8F%B0windows10%20%E4%B8%93%E4%B8%9A%E7%89%88%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E6%97%A0%E6%B3%95%E9%80%9A%E8%BF%87%E5%9C%B0%E5%9D%80%5C192.168.1.1smb%E8%AE%BF%E9%97%AEsamba%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%8C%E5%9C%A8%E9%80%9A%E8%BF%87%E6%98%A0%E5%B0%84%E8%AE%BF%E9%97%AE%E6%97%B6%E9%80%89%E4%B8%AD%E4%BD%BF%E7%94%A8%E5%85%B6%E4%BB%96%E5%87%AD%E6%8D%AE%E8%BF%9E%E6%8E%A5%E6%97%B6%EF%BC%8C%E5%88%99%E5%8F%AF%E4%BB%A5%E6%8F%90%E7%A4%BA%E8%BE%93%E5%85%A5%E7%94%A8%E6%88%B7%E5%90%8D%E5%AF%86%E7%A0%81%EF%BC%8C%E4%BD%86%E8%BE%93%E5%85%A5%E6%AD%A3%E7%A1%AE%E7%9A%84%E7%94%A8%E6%88%B7%E5%90%8D%E5%AF%86%E7%A0%81%EF%BC%8C%E4%BB%8D%E7%84%B6%E6%8F%90%E7%A4%BA%E7%94%A8%E6%88%B7%E5%90%8D%E6%88%96%E5%AF%86%E7%A0%81%E9%94%99%E8%AF%AF