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

image

重啟系統
[root@bogon ~]# reboot

4.檢查firewall狀態

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

image

否則,按照下述操作關閉防火牆
#關閉防火牆
 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.
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

image
【操作過程基本與上述一致,增加更多以此類推】

四、啟動smb

1.啟動smb

[root@samba ~]# systemctl start smb

2.enable開機自動啟動

[root@samba ~]# systemctl enable smb

3.查看服務是否啟動:Active:active(running)代表啟動成功

[root@samba ~]# systemctl status smb

image

五、驗證

1.打開WIN + R
image
2.此處我配置的是免密登錄,因此回車后直接接入共享文件夾
image
【如果配置的是賬號密碼登錄,則會彈出登錄窗口,輸入賬號和密碼即可】
3.不管是windows還是linux創建文檔,實現了同步與共享
image

六、卸載 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已經不存在了
image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM