samba是一个能让Linux系统应用Microsoft网络通讯协议的软件,类似于win的网上邻居,让windows和linux实现文件共享
1.安装smaba服务
yum install samba samba-client samba-swat
装完后:
[root@XXX /] rpm -qa | grep samba
[root@XXX /] rpm -qa | grep samba
Samba服务器安装完毕,会生成配置文件目录/etc/samba和其它一些samba可执行命令工具,/etc/samba/smb.conf是samba的核心配置文件,/etc/init.d/smb是samba的启动/关闭文件。
2.启动、重启、停止、查看服务状态
service smb start
service smb restart
service smb stop
service smb status
service smb start
service smb restart
service smb stop
service smb status
3.配置
Samba的主配置文件为/etc/samba/smb.conf,主配置文件由两部分构成:
Global Settings (55-245行)
该设置都是与Samba服务整体运行环境有关的选项,它的设置项目是针对所有共享资源的。
Share Definitions (246-尾行)
该设置针对的是共享目录个别的设置,只对当前的共享资源起作用。
4.实战
现在将nginx的html目录共享给win。
首先修改配置文件/etc/samba/smb.conf。将该文件底部改成如下:
-----------------------------------------------------------
[html]
comment = Public Stuff
path = /usr/local/nginx/html
create mask = 0777
directory mask = 0777
force create mode = 0777
force directory mode = 0777
force security mode = 0777
abailable = yes
browseable = yes
public = yes
writable = no
write list = +staff
-----------------------------------------------------------
-----------------------------------------------------------
[html]
comment = Public Stuff
path = /usr/local/nginx/html
create mask = 0777
directory mask = 0777
force create mode = 0777
force directory mode = 0777
force security mode = 0777
abailable = yes
browseable = yes
public = yes
writable = no
write list = +staff
-----------------------------------------------------------
然后添加一个samba用户(该用户必须首先是linux用户useradd xxx):
smbpasswd -a xxx
然后输入密码,这时基本配置完成。下面从win打开\\xxx.xxx.xxx.xxx(linux ip地址)然后输入以上配置的用户名密码即可:
firewall-cmd --permanent --add-port=137/tcp
firewall-cmd --permanent --add-port=138/tcp
firewall-cmd --permanent --add-port=139/tcp
firewall-cmd --permanent --add-port=445/tcp
firewall-cmd --permanent --add-port=901/tcp
最后,重载防火墙规则:
firewall-cmd --reload
最后,查一下selinux的samba权限配置: getsebool -a | grep samba
-------------------------------------------------------
最后,重载防火墙规则:
firewall-cmd --reload
最后,查一下selinux的samba权限配置: getsebool -a | grep samba
-------------------------------------------------------
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
tmpreaper_use_samba --> off
use_samba_home_dirs --> off
virt_use_samba --> off
-------------------------------------------------------
我们来修改/usr/local/nginx/html目录权限关闭iptables和selinux:
[root@localhost nginx]# setsebool -P samba_enable_home_dirs=on
[root@localhost nginx]# setsebool -P samba_export_all_rw=on
重启samba服务:
[root@localhost nginx]# setsebool -P samba_export_all_rw=on
重启samba服务:
[root@localhost nginx]# service smb restart