在CentOS7上开启Samba匿名共享

CentOS中内置了Samba 4.1.1导致原有的将security设置为share直接允许匿名访问的方法失效,正确的做法是

vim /etc/samba/smb.conf


security = user
passdb backend = tdbsam
map to guest = Bad User #增加这一句将所有认证失败的用户认为是guest

[share]
        path = /mnt/hdd1
        comment= Test
        browseable = yes
        guest ok = yes
        read only = no
        writable = yes


然后是打开防火墙对应的端口,在打开防火墙之前,我先卸载掉CentOS 7自带的firewalld,用iptables来管理

systemctl stop firewalld
systemctl mask firewalld

安装iptables的service管理程序

yum install iptables-services

用以下命令开关和重启iptables

systemctl [stop|start|restart] iptables

打开几个必须的端口

iptables -I INPUT -m state --state NEW -m udp -p udp --dport 137 -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport 138 -j ACCEPT
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT

把iptables的设置保存起来

/usr/libexec/iptables/iptables.init save

接下来,设置SELinux

chcon -tR samba_share_t /mnt/hdd1/

设置samba共享目录的所有者和权限

chown -R nobody:nobody /mnt/hdd1/ 
(之前不把目录设置为nobody直接导致目录无法访问,纠结了我很久)
chmod -R 777 /mnt/hdd1/ 

done

参考链接:


评论

此博客中的热门博文

远程记录OpenWRT日志

用OpenWRT打造自动翻墙路由器(详解篇)

Python中为什么要用is None来代替== None?