日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

cifs------网络文件系统(2)

發布時間:2023/11/27 windows 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cifs------网络文件系统(2) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

接著上篇博客繼續:

Samba 基本配置

[root@server2 ~]# rpm -qc samba-common???????????? //查看smb的配置文件

1、黑、白名單的設定

默認白名單,設置的ip是黑名單用戶:hosts deny = ip
默認黑名單,設置的ip是白名單用戶:hosts allow = ip

黑名單 :

??????? 假設不允許ip為172.25.1.2的的主機登陸

服務器端 :

[root@server1 ~]# vim /etc/samba/smb.conf?????????? //編輯配置文件

hosts deny = 172.25.1.2

[root@server1 ~]# systemctl restart smb.service???????? //服務重啟

此時,客戶端:

[root@server2 ~]# smbclient -L //172.25.1.1/ -U student???????????????? //服務被拒絕

白名單:

??????? 假設只允許ip為172.25.1.2的的主機登陸

服務器端:

[root@server1 samba]# vim /etc/samba/smb.conf???????????? //將黑名單注釋掉,并添加白名單

[root@server1 ~]# systemctl restart smb.service??????? //重啟服務

此時,客戶端:

[root@server2 ~]#? smbclient //172.25.1.1/student -U student?????????????? //可以登陸

2、smb 共享目錄

非系統目錄的共享

服務器端:

[root@server1 ~]# mkdir /westos

[root@server1 ~]# touch /westos/file{1..5}?????????? //目錄下創建文件

修改安全上下文,這里出現了點問題;

[root@server1 ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?'????????????? //提示沒有semanage這個命令
-bash: semanage: command not found

[root@server1 ~]# yum install -y semanage???

Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
No package semanage available.
Error: Nothing to do

[root@server1 ~]# yum provides semanage???????

Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
rhel7.5/filelists_db????????????????????????????????????????????? | 3.4 MB? 00:00:00??? ?
policycoreutils-python-2.5-22.el7.x86_64 : SELinux policy core python utilities
Repo??????? : rhel7.5
Matched from:
Filename??? : /usr/sbin/semanage

[root@server1 ~]# yum -y install policycoreutils-python

[root@server1 ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?'?????????????? //此時修改安全上下文

[root@server1 ~]# restorecon -FvvR /westos/???????????????????? //刷新

[root@server1 ~]# semanage fcontext -l | grep /westos?????????? //過濾查看/westos的安全上下文修改是否成功

[root@server1 ~]# vim /etc/samba/smb.conf

[DIR]????????????????????? //可以看到的共享目錄的名稱
comment = westos file?? //對共享目錄的描述
path = /westos??? ? ? ? ? ? ? //共享目錄的絕對路徑

[root@server1 ~]# systemctl restart smb.service????????????? //重啟服務

客戶端:

[root@server2 ~]# smbclient //172.25.1.1/DIR?????????????? //匿名登陸
Enter SAMBA\root's password:
Anonymous login successful
tree connect failed: NT_STATUS_ACCESS_DENIED???????????? //登錄失敗,則匿名用戶不可以登陸
[root@server2 ~]# smbclient //172.25.1.1/DIR -U student??????? //student登陸
Enter SAMBA\student's password:
Try "help" to get a list of possible commands.????????????????? //登陸成功
smb: \> ls
? .?????????????????????????????????? D??????? 0? Tue Mar? 5 07:17:42 2019
? ..???????????????????????????????? DR??????? 0? Tue Mar? 5 07:16:09 2019
? file1?????????????????????????????? N??????? 0? Tue Mar? 5 07:17:42 2019
? file2?????????????????????????????? N??????? 0? Tue Mar? 5 07:17:42 2019
? file3?????????????????????????????? N??????? 0? Tue Mar? 5 07:17:42 2019
? file4?????????????????????????????? N??????? 0? Tue Mar? 5 07:17:42 2019
? file5?????????????????????????????? N??????? 0? Tue Mar? 5 07:17:42 2019

?? ??? ?17811456 blocks of size 1024. 16542024 blocks available
smb: \> quit???????????????? //退出

系統目錄的共享

服務端:

[root@server1 ~]# vim /etc/samba/smb.conf

[root@server1 ~]# systemctl restart smb.service????????????????
[root@server1 ~]# setsebool -P samba_export_all_ro on????????????? //打開該布爾值后可以共享所有目錄,比安全上下文的級別高

[root@server1 ~]# ls /mnt
westos

客戶端:

[root@server2 ~]# smbclient //172.25.1.1/DIR -U student

smb 權限管理

browseable = no | yes ——更改此參數,不用重啟服務
no ——將該共享目錄設置為隱藏
yes——將該共享目錄設置為顯示
writable = yes|no ——更改此參數,需要重啟服務

no | yes —— 設置用戶是否可寫(所有用戶)
write list = student ——更改此參數,需要重啟服務

允許用戶 student 進行寫操作(相當于白名單)
write list = @student ——更改此參數,需要重啟服務

只允許屬于 student 組的用戶進行寫操作
admin users = 用戶名 ——更改此參數,需要重啟服務

1.隱藏該共享目錄

服務端:

[root@server1 ~]# vim /etc/samba/smb.conf

[root@server1 ~]# systemctl restart smb.service

客戶端:

[root@server2 ~]#? smbclient -L //172.25.1.1

2.顯示該共享目錄,且可寫

服務器端:

[root@server1 ~]# vim /etc/samba/smb.conf

[root@server1 ~]# systemctl restart smb.service

[root@server1 ~]# chmod 777 /mnt

客戶端:

[root@server2 ~]# mount //172.25.1.1/DIR /mnt -o username=student,password=redhat

[root@server2 ~]# mount //172.25.1.1/DIR /mnt -o username=student,password=redhat
[root@server2 ~]# cd /mnt/
[root@server2 mnt]# ls
westos
[root@server2 mnt]# touch file1
[root@server2 mnt]# ls
file1? westos

[root@server2 mnt]# cd
[root@server2 ~]# umount /mnt/


**************************************

以此類推。。。。。。

smb 多用戶掛載

客戶端:

[root@server2 ~]# yum install cifs-utils -y

[root@server2 ~]# vim /root/smbpass?????????????? //根據掛載規則編寫認證所需的文件

[root@server2 ~]# mount -o credentials=/root/smbpass,sec=ntlmssp,multiuser //172.25.1.1/DIR /mnt

//掛載,其中,credentials=/root/smbpass文件指定的用戶名、密碼,sec=ntlmssp 認證方式認證方式是ntlmssp;查詢方式:rpm -ql | grep samba, multiuser為多用戶掛載

[root@server2 ~]# df

[root@server2 ~]# cd /mnt/
[root@server2 mnt]# ls
file1? westos
[root@server2 mnt]# useradd file2??????? //創建用戶file2
[root@server2 mnt]# su - file2???????? //切換到普通用戶file2
[file2@server2 ~]$ cd /mnt?????????????
[file2@server2 mnt]$ ls???????? //無法查看 ,必須指定用戶掛載通過smb認證才可以查看

ls: reading directory .: Permission denied
[file2@server2 mnt]$ exit
logout

[root@server2 mnt]# cifscreds --help????????? //查看相關命令

cifscreds: unrecognized option '--help'
Usage:
?? ?cifscreds add [-u username] [-d] <host|domain>
?? ?cifscreds clear [-u username] [-d] <host|domain>
?? ?cifscreds clearall
?? ?cifscreds update [-u username] [-d] <host|domain>

[root@server2 mnt]# su - file2
Last login: Tue Mar? 5 10:02:55 EST 2019 on pts/0
[file2@server2 ~]$ cifscreds add -u student 172.25.1.1??????????????? //需要通過smb認證
Password:
[file2@server2 ~]$ cd /mnt/
[file2@server2 mnt]$ ls??????????? //此時可以查看mnt下面的文件

file1? westos

smb 匿名用戶訪問

服務器端:

[root@server1 ~]# vim /etc/samba/smb.conf

[root@server1 ~]# systemctl restart smb.service


客戶端:

[root@server2 mnt]$ smbclient //172.25.1.1/DIR

//即匿名用戶此時可以訪問到

[root@server2 ~]# mount //172.25.1.1/DIR /mnt -o username=guest,password=""

總結

以上是生活随笔為你收集整理的cifs------网络文件系统(2)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

歡迎分享!

轉載請說明來源于"生活随笔",并保留原作者的名字。

本文地址:cifs------网络文件系统(2)