1. 程式人生 > >linux學習 lesson23CIFS檔案系統

linux學習 lesson23CIFS檔案系統

一、基本概念:

CIFS是實現檔案共享服務的一種檔案系統,主要用於實現windows系統中的檔案共享,linux系統中用的比較少linux系統中利用CIFS檔案系統實現檔案共享,需要安裝samba服務。它使程式可以訪問遠端Internet計算機上的檔案並要求此計算機提供服務。CIFS 使用客戶/伺服器模式。客戶程式請求遠在伺服器上的伺服器程式為它提供服務。伺服器獲得請求並返回響應。CIFS是公共的或開放的SMB協議版本,並由Microsoft使用。SMB協議在區域網上用於伺服器檔案訪問和列印的協議。像SMB協議一樣,CIFS在高層執行,而不像TCP/IP協議那樣執行在底層。CIFS可以看做是應用程式協議如檔案傳輸協議和超文字傳輸協議的一個實現。

CIFS 可以使您達到以下功能:

1.訪問伺服器本地檔案並讀寫這些檔案

2.與其它使用者一起共享一些檔案塊

3.在斷線時自動恢復與網路的連線

4.使用統一碼(Unicode)檔名:檔名可以使用任何字符集,而不侷限於為英語或西歐語言設計的字符集。
windowns中

二、安裝samba服務

yum install samba-common samba samba-client -y
在這裡插入圖片描述

firewall-cmd --permanent --add-service=samba         
firewall-cmd --permanent --add-service=samba-client      ##火牆允許服務執行 
firewall-cmd --reload                                    ##重新讀取火牆

systemctl start smb                 ##開啟samba
systemctl enable smb                ##開機啟動

在這裡插入圖片描述
smbclient -L /172.25.254.208 ##匿名登陸samba
在這裡插入圖片描述
安裝完成!

三、samba使用者管理

 smbpasswd -a kris        ##新增samba使用者,使用者必須是本地存在使用者

在這裡插入圖片描述

 smbpasswd -a hello       ##使用者不存在則不能新增

在這裡插入圖片描述
顯示失敗

pdbedit -L                ##列出samba使用者

在這裡插入圖片描述
kris新增成功。

新增:

smbpasswd -a student ##使用者必須存在
pdbedit -L ##檢視使用者
刪除:
smbpasswd -x student
pdbedit -L
在這裡插入圖片描述

四、samba訪問控制

cd /home/kris/
touch file{1..10}
smbclient  //172.25.254.208/kris -U kris        ##檢視/kris中家目錄的內容

在這裡插入圖片描述
無法檢視

開啟許可權

getsebool -a | grep samba
setsebool -P samba_enable_home_dirs on   ##開啟許可權,關閉samba使用者訪問目錄限制

在這裡插入圖片描述

smbclient //172.25.254.208/kris -U kris ##檢視/kris中家目錄的內容

在這裡插入圖片描述
可以顯示檔案證明成功

samba非本機訪問控制

samba主配置檔案:/etc/samba/smb.conf

白名單:

vim /etc/samba/smb.conf
96         hosts allow =172.25.254.8  ##只允許8訪問

在這裡插入圖片描述
systemctl restart smb.service
測試:
在8主機上進行掛載:
mount //172.25.254.208/student /mnt/ -o username=student,passwd=student
在這裡插入圖片描述

黑名單:

vim /etc/samba/smb.conf
96         hosts deny =172.25.254.8  ##只拒絕8訪問

在這裡插入圖片描述

systemctl restart smb.service
測試:
[[email protected] ~]# mount //172.25.254.208/student /mnt/ -o

在這裡插入圖片描述

五、域名顯示

smbclient -L //172.25.254.208 #檢視原域名是MYGROUP
vim /etc/samba/smb.conf
89 workgroup = KRIS

systemctl restart smb
smbclient -L //172.25.254.208
Enter root’s password:
Anonymous login successful
Domain=[KRIS] OS=[Unix] Server=[Samba 4.1.1]

Sharename       Type      Comment
---------       ----      -------
IPC$            IPC       IPC Service (Samba Server Version 4.1.1)
Anonymous login successful
Domain=[KRIS] OS=[Unix] Server=[Samba 4.1.1]

Server               Comment
---------            -------

Workgroup            Master
---------            -------

Domain發生改變。

六、samba檔案共享

mkdir /kris                 ##建立共享目錄
touch /kris/file{1..10}     ##新建檔案
vim /etc/samba/smb.conf

在這裡插入圖片描述

[share] ##共享目錄名稱
comment = share kris dir ##目錄說明
path = /kris ##共享目錄地址(指定共享目錄)
在這裡插入圖片描述

systemctl restart smb

semanage fcontext -a -t samba_etc_t '/kris(/.*)?'         ##修改安全上下文
restorecon -RvvF /kris/

測試:
smbclient //172.25.254.208/share -U kris 有檔案在共享成功!
在這裡插入圖片描述

系統目錄共享

vim /etc/samba/smb.conf

在這裡插入圖片描述

getsebool -a | grep samba
setsebool -P samba_export_all_ro on        ##開啟只讀開關
systemctl restart smb.service

smbclient //172.25.254.208/HAHAHAHA -U kris
可以顯示
在這裡插入圖片描述

使共享檔案可以讀寫:

vim /etc/samba/smb.conf

在這裡插入圖片描述

mount //172.25.254.208/share /mnt/ -o username=kris,password=123      ##將分享目錄以kris身份掛載到/mnt上
chmod 777 /kris      ##改變許可權

在這裡插入圖片描述

其他設定(在配置檔案中)
write list = kris ##只有kris可寫
write list = +kris write list = @kris ##屬於kris組的使用者可寫
browseable = no ##隱藏但可用
vaild users = kris ##有效使用者
admin users = kris ##使用者kris作為該目錄的超級使用者

guest ok = yes ##匿名使用者可登陸
guest是指windows的匿名使用者 linux的匿名使用者是anonmours 所以在配置檔案前要對guest進行宣告。 map to guest = bad user

七、多使用者掛載