安装Samba
yum
install
samba samba-client samba-common -y
备份原始的Samba配置文件:
mv /etc/samba/smb
.conf
/etc/samba/smb
.conf.bak
編輯conf文件:
vim
/etc/samba/smb
.conf
[global]
workgroup = WORKGROUP
server string = Samba Server %
v
netbios name = centos
security = user
map to guest = bad user
dns proxy = no
#============================ Share Definitions ==============================
[Anonymous]
path = /home
/samba/anonymous
browsable =
yes
writable =
yes
guest ok =
yes
read
only = no
:wq
#保存并退出
建立anonymous文件夾
mkdir
-p
/home/samba/anonymous
systemctl
enable
smb.service
systemctl
enable
nmb.service
systemctl restart smb.service
systemctl restart nmb.service
防火墙開放Samba的访问
firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload
现在可以在Windows中访问CentOS7的共享文件了,在命令提示行中输入:\IP
下面是浏览到的文件夹,如果你尝试着去创建一个文件,你会得到一个没有权限的错误信息、
給予共享文件夹匿名用户权限:#匿名用戶可读写执行#拥有者匿名用户
cd
/home/samba
chmod
-R 0755 anonymous/
chown
-R nobody:nobody anonymous/
进一步我们需要配置Selinux
chcon -t samba_share_t anonymous/
***
chcon命令:
修改对象(文件)的安全上下文
命令格式:
Chcon [OPTIONS…] CONTEXT FILES…..
Chcon [OPTIONS…] –reference=PEF_FILES FILES…
说明:
CONTEXT 为要设置的安全上下文
FILES 对象(文件)
--reference 参照的对象
PEF_FILES 参照文件上下文
FILES 应用参照文件上下文为我的上下文。
OPTIONS 如下:
-f 强迫执行
-R 递归地修改对象的安全上下文
-r ROLE 修改安全上下文角色的配置
-t TYPE 修改安全上下文类型的配置
-u USER 修改安全上下文用户的配置
-v 显示冗长的信息
**********************************快速一览******************************************************
yum install samba samba-client samba-common –y && mv /etc/samba/smb.conf /etc/samba/smb.conf.bk2
echo '[global]' >> /etc/samba/smb.conf
echo 'workgroup = WORKGROUP' >> /etc/samba/smb.conf
echo 'server string = Samba Server %v' >> /etc/samba/smb.conf
echo 'netbios name = centos' >> /etc/samba/smb.conf
echo 'security = user' >> /etc/samba/smb.conf
echo 'map to guest = bad user' >> /etc/samba/smb.conf
echo 'dns proxy = no' >> /etc/samba/smb.conf
echo '#============================ Share Definitions ============================== ' >> /etc/samba/smb.conf
echo '[Anonymous]' >> /etc/samba/smb.conf
echo 'path = /home/samba/anonymous' >> /etc/samba/smb.conf
echo 'browsable =yes' >> /etc/samba/smb.conf
echo 'writable = yes' >> /etc/samba/smb.conf
echo 'guest ok = yes' >> /etc/samba/smb.conf
echo 'read only = no' >> /etc/samba/smb.conf
mkdir -p /home/samba/anonymous
systemctl enable nmb.service
systemctl enable nmb.service
systemctl restart smb.service
systemctl restart nmb.service
firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload
cd /home/samba
chmod -R 0755 anonymous/
chown -R nobody:nobody anonymous/
chcon -t samba_share_t anonymous/