CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)

Samba服务器通信协议(Server Messages Block)就是是为了解决局域网内的文件或打印机等资源的共享服务问题,让多个主机之间共享文件变成越来越简单

一、前置条件

1.Linux和Windows系统之间网络能互通

[root@samba ~]# ping 192.168.205.89
PING 192.168.205.89 (192.168.205.89) 56(84) bytes of data.
64 bytes from 192.168.205.89: icmp_seq=1 ttl=125 time=0.570 ms
64 bytes from 192.168.205.89: icmp_seq=2 ttl=125 time=0.497 ms
64 bytes from 192.168.205.89: icmp_seq=3 ttl=125 time=1.08 ms
64 bytes from 192.168.205.89: icmp_seq=4 ttl=125 time=1.36 ms
64 bytes from 192.168.205.89: icmp_seq=5 ttl=125 time=0.498 ms
64 bytes from 192.168.205.89: icmp_seq=6 ttl=125 time=0.615 ms
64 bytes from 192.168.205.89: icmp_seq=7 ttl=125 time=0.511 ms
64 bytes from 192.168.205.89: icmp_seq=8 ttl=125 time=2.72 ms

2.检查linux系统版本

[root@samba ~]# cat /etc/redhat-release
CentOS Linux release 8.3.2011

3.检查selinux状态

[root@samba ~]# getenforce
Disabled
【此状态为关闭状态,若不是请按如下操作】
关闭SELINUX
[root@bogon ~]# vim /etc/sysconfig/selinux

CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)

重启系统
[root@bogon ~]# reboot

4.检查firewall状态

[root@samba ~]# firewall-cmd --state

CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)

否则,按照下述操作关闭防火墙
#关闭防火墙
 systemctl stop firewalld
#开机禁用防火墙
 systemctl disable firewalld

二、安装samba服务端

1.检查linux系统是否安装了Samba

[root@samba ~]# rpm -qa|grep samba

CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)
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.
Dependencies resolved.
=============================================================================================================================================================
 Package                                      Architecture                     Version                                Repository                        Size
=============================================================================================================================================================
Installing:
 samba                                        x86_64                           4.13.3-3.el8                           baseos                           846 k
Installing dependencies:
 libwbclient                                  x86_64                           4.13.3-3.el8                           baseos                           119 k
 samba-client-libs                            x86_64                           4.13.3-3.el8                           baseos                           5.4 M
 samba-common                                 noarch                           4.13.3-3.el8                           baseos                           218 k
 samba-common-libs                            x86_64                           4.13.3-3.el8                           baseos                           171 k
 samba-common-tools                           x86_64                           4.13.3-3.el8                           baseos                           498 k
 samba-libs                                   x86_64                           4.13.3-3.el8                           baseos                           168 k

Transaction Summary
=============================================================================================================================================================
Install  7 Packages

Total download size: 7.4 M
Installed size: 25 M
Downloading Packages:
(1/7): libwbclient-4.13.3-3.el8.x86_64.rpm                                                                                   2.6 MB/s | 119 kB     00:00    
(2/7): samba-4.13.3-3.el8.x86_64.rpm                                                                                          11 MB/s | 846 kB     00:00    
(3/7): samba-common-4.13.3-3.el8.noarch.rpm                                                                                  5.1 MB/s | 218 kB     00:00    
(4/7): samba-common-libs-4.13.3-3.el8.x86_64.rpm                                                                              10 MB/s | 171 kB     00:00    
(5/7): samba-libs-4.13.3-3.el8.x86_64.rpm                                                                                    7.5 MB/s | 168 kB     00:00    
(6/7): samba-common-tools-4.13.3-3.el8.x86_64.rpm                                                                             11 MB/s | 498 kB     00:00    
(7/7): samba-client-libs-4.13.3-3.el8.x86_64.rpm                                                                              35 MB/s | 5.4 MB     00:00    
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                         13 MB/s | 7.4 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                     1/1 
  Running scriptlet: samba-common-4.13.3-3.el8.noarch                                                                                                    1/7 
  Installing       : samba-common-4.13.3-3.el8.noarch                                                                                                    1/7 
  Running scriptlet: samba-common-4.13.3-3.el8.noarch                                                                                                    1/7 
  Installing       : samba-client-libs-4.13.3-3.el8.x86_64                                                                                               2/7 
  Installing       : libwbclient-4.13.3-3.el8.x86_64                                                                                                     3/7 
  Installing       : samba-common-libs-4.13.3-3.el8.x86_64                                                                                               4/7 
  Installing       : samba-libs-4.13.3-3.el8.x86_64                                                                                                      5/7 
  Installing       : samba-common-tools-4.13.3-3.el8.x86_64                                                                                              6/7 
  Installing       : samba-4.13.3-3.el8.x86_64                                                                                                           7/7 
  Running scriptlet: samba-4.13.3-3.el8.x86_64                                                                                                           7/7 
  Running scriptlet: libwbclient-4.13.3-3.el8.x86_64                                                                                                     7/7 
  Running scriptlet: samba-4.13.3-3.el8.x86_64                                                                                                           7/7 
  Verifying        : libwbclient-4.13.3-3.el8.x86_64                                                                                                     1/7 
  Verifying        : samba-4.13.3-3.el8.x86_64                                                                                                           2/7 
  Verifying        : samba-client-libs-4.13.3-3.el8.x86_64                                                                                               3/7 
  Verifying        : samba-common-4.13.3-3.el8.noarch                                                                                                    4/7 
  Verifying        : samba-common-libs-4.13.3-3.el8.x86_64                                                                                               5/7 
  Verifying        : samba-common-tools-4.13.3-3.el8.x86_64                                                                                              6/7 
  Verifying        : samba-libs-4.13.3-3.el8.x86_64                                                                                                      7/7 

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 myshare
[root@samba home]# passwd myshare
Changing password for user myshare.
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
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[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
[share]
        path = /home/myshare//共享目录的路径
        writable = yes //取消此句不可写入,只能浏览
        guest ok = yes//取消此句不可浏览,提示没有权限

6.增加共享目录文件的操作

[root@samba opt]# mkdir Download
[root@samba opt]# chown -R myshare /opt/Download/
[root@samba opt]# chgrp -R myshare /opt/Download/
[root@samba opt]# chmod -R 777 /opt/Download/
[root@samba myshare]# vim /etc/samba/smb.conf

CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)
【操作过程基本与上述一致,增加更多以此类推】

四、启动smb

1.启动smb

[root@samba ~]# systemctl start smb

2.enable开机自动启动

[root@samba ~]# systemctl enable smb

3.查看服务是否启动:Active:active(running)代表启动成功

[root@samba ~]# systemctl status smb

CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)

五、验证

1.打开WIN + R
CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)
2.此处我配置的是免密登录,因此回车后直接接入共享文件夹
CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)
【如果配置的是账号密码登录,则会弹出登录窗口,输入账号和密码即可】
3.不管是windows还是linux创建文档,实现了同步与共享
CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)

六、卸载 samba

第一、 首先检查Samba服务包

rpm -qa | grep samba

CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)
第二、逐个删除,输入命令#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已经不存在了
CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输)

上一篇:查看Ubantu版本信息


下一篇:查看linux版本