centos 8.4上配置SMB 设置共享文件给Windows使用的记录

CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)
Samba服务器通信协议(Server Messages Block)就是是为了解决局域网内的文件或打印机等资源的共享服务问题,让多个主机之间共享文件变成越来越简单

一、前置条件
1.Linux和Windows系统之间网络能互通
2.检查linux系统版本
[root@samba ~]# cat /etc/redhat-release
CentOS Linux release 8.3.2011
[root@samba ~]# firewall-cmd --state
否则,按照下述操作关闭防火墙
#关闭防火墙
systemctl stop firewalld
#开机禁用防火墙
systemctl disable firewalld
二、安装samba服务端
1.检查linux系统是否安装了Samba

[root@samba ~]# rpm -qa|grep samba
image
2.安装Samba
[root@samba ~]# yum install -y samba
Last metadata expiration check: 2:58:07 ago on Fri 16 Jul 2021 02:55:28 PM CST.

Installed:
libwbclient-4.13.3-3.el8.x86_64 samba-4.13.3-3.el8.x86_64 samba-client-libs-4.13.3-3.el8.x86_64 samba-common-4.13.3-3.el8.noarch
samba-common-libs-4.13.3-3.el8.x86_64 samba-common-tools-4.13.3-3.el8.x86_64 samba-libs-4.13.3-3.el8.x86_64
Complete!
完成安装:

三、配置samba服务端
1.创建smb的访问账户和密码

[root@samba home]# adduser blues (新增加用户)
[root@samba home]# passwd blues (设置密码)
Changing password for user blues.
New password:
BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.
2.设置文件所有者和文件关联组的,-R : 处理指定目录以及其子目录下的所有文件
[root@samba home]# chown -R myshare /home/myshare/
3.变更文件或目录的所属群组
[root@samba home]# chgrp -R myshare /home/myshare/
4.控制用户对文件的权限的命令
[root@samba home]# chmod -R 777 /home/myshare/
5.修改/etc/samba/smb.conf文件,配置共享文件

[root@samba myshare]# vim /etc/samba/smb.conf
[global]
workgroup = SAMBA
security = user
map to guest = Bad User //可以查看共享的根文件夹名,如果删除,登陆服务器就需要用户名和密码
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
-----------------------------------以上是系统默认带的,—以下是新增加共享部门可以VI直接添加
[date]
comment = sbm
path = /home/date
writable = yes
guest ok = no
valid users=blues (blues是用户名)

四、启动smb
1.启动smb
[root@samba ~]# systemctl start sm

2.enable开机自动启动
[root@samba ~]# systemctl enable smb

3.查看服务是否启动:Active:active(running)代表启动成功
[root@localhost ~]# systemctl status smb
● smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2021-11-12 20:06:48 EST; 6s ago
Docs: man:smbd(8)
man:samba(7)
man:smb.conf(5)
Main PID: 6927 (smbd)
Status: “smbd: ready to serve connections…”
Tasks: 4 (limit: 100948)
Memory: 10.3M
CGroup: /system.slice/smb.service
├─6927 /usr/sbin/smbd --foreground --no-process-group
├─6929 /usr/sbin/smbd --foreground --no-process-group
├─6930 /usr/sbin/smbd --foreground --no-process-group
└─6931 /usr/sbin/smbd --foreground --no-process-group
11月 12 20:06:48 localhost.localdomain systemd[1]: Starting Samba SMB Daemon…
11月 12 20:06:48 localhost.localdomain smbd[6927]: [2021/11/12 20:06:48.790072, 0] …/…/lib/util/become_daemon.c:136(daemon_ready)
11月 12 20:06:48 localhost.localdomain smbd[6927]: daemon_ready: daemon ‘smbd’ finished starting up and ready to serve connections
11月 12 20:06:48 localhost.localdomain systemd[1]: Started Samba SMB Daemon.

[root@localhost ~]# reboot
Connection closing…Socket close.
Connection closed by foreign host.
Disconnected from remote host(192.168.0.12) at 09:07:45.
Type `help’ to learn how to use Xshell prompt.

五、卸载 samba
第一、 首先检查Samba服务包

rpm -qa | grep samba

image
第二、逐个删除,输入命令#rpm -e samba

[root@samba ~]# rpm -e samba-common-tools-4.13.3-3.el8.x86_64

第三、逐个删除,输入命令#rpm -e samba

[root@samba ~]# rpm -e samba-libs-4.13.3-3.el8.x86_64
第四、剩下的可能删不掉,则使用rpm -e --nodeps去删除

[root@samba ~]# rpm -e --nodeps samba-client-libs-4.13.3-3.el8.x86_64

[root@samba ~]# rpm -e --nodeps samba-common-libs-4.13.3-3.el8.x86_64

[root@samba ~]# rpm -e --nodeps samba-common-4.13.3-3.el8.noarch
samba已经不存在了

其他问题解决:
如果确定防火墙设置没问题,samba设置也没问题,而且samba也已经启动了,也保证共享目录读写权限没问题,那问题八成就是selinux禁止了samba的行为。
解决办法:
输入getenforce命令查看selinux的状态
[root@localhost ~]# getenforce
Enforcing
进行如下设置暂时设置为permissive,注意这个设置方式是暂时的
[root@localhost ~]# setenforce 0
然后在查看
[root@localhost ~]# getenforce
Permissive
如果怕永久设置为permissive,进行如下修改
[root@localhost ~]# vim /etc/selinux/config
修改为SELINUX=permissive
:wq!
保存重启

问题解决

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值