通过Samba服务实现Linux文件共享到Windows

1.用yum命令安装Samba服务
# yum install samba

2.配置访问共享资源的用户(如root,该账户一定要本来就在当前系统就存在的,我们用的root这肯定存在了)
# pdbedit -a -u root (会提示我们输入密码和确认密码,注意此处的输入密码是输入该账户在Samba服务数据库中的密码,这和root账户的系统密码是不一样的概念,我是设置的一样的)

3.创建共享目录同时赋予访问共享资源用户对该文件的权限。

# mkdir /home/database --创建目录
# chown -Rf root:root /home/database --赋权限
# semanage fcontext -a -t samba_share_t /home/database --修改 database 目录的 SELinux 安全上下文
# restorecon -Rv /home/database --恢复SELinux文件属性,使上面修改操作立刻生效

4.设置 SELinux 服务与策略,使其允许通过 Samba 服务程序访问普通用户家目录。(由于我们使用的是root用户,所以就算我们执行了这一步操作也无权限访问root目录)
# getsebool -a | grep samba --查看Samba 服务程序相关的 SELinux 域策略
# setsebool -P samba_enable_home_dirs on --允许通过 Samba 服务程序访问普通用户家目录

5.修改Samba 服务程序的主配置文件,我们只需要改[global]这一个参数,和新建一个[database]参数就行,其他不用动,刘遄老师说可以删掉[homes]和[printers]参数,这里我是没有删。
# vim /etc/samba/smb.conf
[global]
workgroup = MYGROUP
server string = Samba Server Version %v
log file = /var/log/samba/log.%m
max log size = 50
security = user
passdb backend = tdbsam
load printers = yes
cups options = raw
[database]
comment = Do not arbitrarily modify the database file
path = /home/database
public = no
writable = yes

6.重启 smb 服务(Samba 服务程序在 Linux 系统中的名字为 smb)并清空 iptables 防火墙
# systemctl restart smb --重启smb服务
# systemctl enable smb --使smb服务自动启动
# iptables -F --清空iptables防火墙
# service iptables save --对iptables服务进行保存(注1)

linux上的共享配置工作就已经完成,接下来就是去Windows上访问试试了,打开运行窗口输入\\ip,再输入我们配置的共享用户:root再输入密码就可以访问共享文件夹了。


注1:如果输入# service iptables save之后提示"The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl."
解决办法:

1.先执行如下命令:

systemctl stop firewalld

systemctl mask firewalld

2.安装iptables services

yum install iptables-services

3.设置开机启动

systemctl enable iptables

4.重启iptables service

systemctl restart iptables

5.执行保存配置命令

service iptables save

猜你喜欢

转载自www.cnblogs.com/kjjmj/p/10178945.html
今日推荐