环境

  1. [root@manager ~]# cat /etc/redhat-release
  2. CentOS Linux release 7.6.1810 (Core)
[root@manager ~]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.20  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe32:8c15  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:32:8c:15  txqueuelen 1000  (Ethernet)
        RX packets 34928  bytes 6427975 (6.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19629  bytes 2128483 (2.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 88  bytes 5952 (5.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 88  bytes 5952 (5.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

1.安装samba

[root@manager data]# yum install samba samba-client -y

2.修改smb.conf为以下内容

[root@manager samba]# cat /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.

[global]
        workgroup = SAMBA
        security = user
        guest account = nobody
        passdb backend = tdbsam
        log file = /var/log/samba/log.%m
        map to guest = Bad User

[public]
        comment = public
        path = /data/samba
        public = yes
        writable = yes
        browseable = yes 
        guest ok = yes

3.创建相关目录

[root@manager samba]# mkdir -p /data/samba/
[root@manager samba]# chmod 777 /data/samba/

4.启动samba

[root@manager samba]# systemctl restart smb
[root@manager samba]# systemctl enable smb
[root@manager samba]# systemctl status smb
● smb.service - Samba SMB Daemon
   Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-09-01 17:19:55 CST; 47s ago
     Docs: man:smbd(8)
           man:samba(7)
           man:smb.conf(5)
 Main PID: 18193 (smbd)
   Status: "smbd: ready to serve connections..."
   CGroup: /system.slice/smb.service
           ├─18193 /usr/sbin/smbd --foreground --no-process-group
           ├─18195 /usr/sbin/smbd --foreground --no-process-group
           ├─18196 /usr/sbin/smbd --foreground --no-process-group
           ├─18204 /usr/sbin/smbd --foreground --no-process-group
           └─18206 /usr/sbin/smbd --foreground --no-process-group

Sep 01 17:19:54 manager systemd[1]: Starting Samba SMB Daemon...
Sep 01 17:19:55 manager smbd[18193]: [2021/09/01 17:19:55.330852,  0] ../../lib/util/become_daemon.c:136(daemon_ready)
Sep 01 17:19:55 manager smbd[18193]:   daemon_ready: daemon 'smbd' finished starting up and ready to serve connections
Sep 01 17:19:55 manager systemd[1]: Started Samba SMB Daemon.

测试验证

win10

60CA853C-8DA8-4207-BC81-EFB941F79CB1.png

7D2A7965-5586-4265-A133-DD58EE5A7F51.png

8183B13D-1D07-4808-8867-448C820BBF4C.png

win10 匿名访问samba可能会有这个报错

F63CA177-21E3-4e7a-A3F6-641DD5257BDB.png

解决方法(推荐方法二)

方法一

按win+R 运行:输入”gpedit.msc” 打开组策略—计算机配置—管理模板—网络—Lanman工作站—启用不安全的来宾登录—选择已启用,设置完成后重启win10

EDD16F7B-F78D-4b79-B90B-D1F707A2F06D.png

方法二

将以下文本编辑保存为 start_smb_guest.reg ,然后双击运行即可。

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters]
"AllowInsecureGuestAuth"=dword:00000001

6E3ECB9E-9CA3-4684-968F-1ABC11268C45.png

参考文档:https://www.cnblogs.com/wucongzhou/p/12614240.html