ubuntu server搭建smb服务共享文件

   

服务器:ubuntu server 18.04
samba版本:Version 4.7.6-Ubuntu

SMB协议旨在解决局域网内的文件或打印机等资源的共享问题,一般不会在服务器上部署,使用场景一般是需要linux设备和win设备共享文件时,由于配置简单、使用方便,很受欢迎。

1 首先安装Samba

#  apt-get install samba

2 修改samba配置文件

为了方便阅读,把空行和注释都过滤掉,然后修改

# mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
# cat /etc/samba/smb.conf.bak | grep -v "#" | grep -v ";" | grep -v "^$" > /etc/samba/smb.conf
# cat /etc/samba/smb.conf
[global]
   workgroup = WORKGROUP
   server string = %h server (Samba, Ubuntu)
   dns proxy = no
   log file = /var/log/samba/log.%m
   max log size = 1000
   syslog = 0
   panic action = /usr/share/samba/panic-action %d
   server role = standalone server
   passdb backend = tdbsam
   obey pam restrictions = yes
   unix password sync = yes
   passwd program = /usr/bin/passwd %u
   passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
   pam password change = yes
   map to guest = bad user
   usershare allow guests = yes
[printers]
   comment = All Printers
   browseable = no
   path = /var/spool/samba
   printable = yes
   guest ok = no
   read only = yes
   create mask = 0700
[print$]
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   read only = yes
   guest ok = no
# vim /etc/samba/smb.conf
...
...
[share]  #共享参数
   comment = samba home directory  #描述信息 
   path = /var/lib/samba/printers #共享目录
   browseable = yes  #指定共享信息是否在“网上邻居”中可见
   public = yes #指定该共享是否允许guest账户访问
   writable = yes ##允许写
   create mask = 0777  #新创建的文件权限
   directory mask = 0777  #新创建的目录权限
   available = yes #指定该共享资源是否可用
   security = share #安全级别为最低

3 重启进程

# service samba* restart

4 调整权限

# chmod 777 /var/lib/samba/printers

常见错误

1 SELinux导致的, setenforce 0; 试试

2 当你修改共享目录的权限时,它的上级目录、上上级目录是否也可以被访问

3 linux与win之间能否ping通

4 smbd进程是否正常运行

5 win10拒绝访问,权限问题,执行
smbclient //192.168.1.106/Sharefolder/共享文件夹,如果可以正常访问,说明是windows的问题,可能是防火墙

6 如果不在上面之列,查看var/log/samba/日志文件

发表评论