Linux學習篇第三章之~samba

--------------------------------------------------------samba------------------------------------------------------------
1.samba作用

提供cifs協議實現共享文件

通用Internet文件系統(CIFS)也稱爲服務器信息塊(SMB),是適用於MicrosoftWindows服務器和客戶端的標準文件和打印機共享系統。Samba服務可用於將Linux文件系統作爲CIFS/SMB網絡文件共享進行共享,並將Linux打印機作爲CIFS/SMB打印機共享進行共享。

2.安裝
yum install samba samba-commn samba-client -y
systemctl start smb nmb
systemctl enable smb nmb
3.添加smb用戶(smb用戶必須是本地用戶)
systemctl stop firewalld
smbpasswd -a student
               
[root@localhost ~]# pdbedit -L         ##查看smb用戶信息
[root@localhost ~]# pdbedit -x smb     ##刪除smb用戶
setsebool -P samba_enable_home_dirs on ##在selinux中設定smb用戶可以訪問自己的家目錄
4.共享目錄的基本設定
 mkdir /smbshare
 touch /smbshare/westosxxx
 vim /etc/samba/smb.conf
               [hha]   ##共享名稱
                comment = local directory  對共享目錄的描述

               path = /smbshare           共享目錄的絕對路徑


> 當共享目錄爲用戶自己建立目錄時
semanage fcontext -a -t samba_share_t '/smbshare(/.*)?'
restorecon -RvvF /smbshare
systemctl restart smb.service
測試:
[kiosk@foundation43 Desktop]$ smbclient //172.25.254.143/hha -U student

> 當共享目錄爲系統建立目錄時
setsebool -P samba export_all_ro on   ##只讀共享
setsebool -P samba export_all_rw on  ##讀寫共享
touch /mnt/file{1..10}
systemctl restart smb.service
測試:

5.samba的配置參數
> 匿名用戶訪問
vim /etc/samba/smb.conf
            [hha]
             comment = local directory
             path = /mnt
             guest ok = yes

             hosts deny = bad user


測試:
[kiosk@foundation43 Desktop]$ smbclient //172.25.254.143/hha    ##匿名用戶登陸                      

> 訪問控制
hosts allow =      ##僅允許
hosts deny =       ##僅拒絕
valid users =      ##當前共享的有效用戶
valid users = @westos  ##當前共享的有效用戶爲westos組
valid users = +westos  ##當前共享的有效用戶爲westos組

server:

vim /etc/samba/smb.conf


useradd westos -s /sbin/nologin

smbpasswd -a westos

usermod -G westos student
usermod -G westos student
 

測試:


> 讀寫控制(所有用戶可寫)
chmod o+w /mnt
setsebool -P samba_export_all_rw on
vim /etc/samba/smb.conf
  [hha]
  comment = local directory
  path = /mnt
  writable = yes
systemctl restart smb.service
測試:
 
(設定指定用戶可寫)
write list = student             ##可寫用戶
write list = +student           ##可寫用戶組
write list = @student
admin users = westos         ##共享的超級用戶指定

測試:


6.smb多用戶掛載(client)

[root@foundation155 ~]# vim /root/haha


[root@foundation155 ~]# chmod 600 /root/haha
[root@foundation155 ~]# yum install cifs-utils -y
[root@foundation155 ~]# mount -o credentials=/root/haha,multiuser,sec=ntlmssp //172.25.254.143/haha /mnt

##credentials=/root/haha 指定掛載時所用到的用戶文件
##multiuser                 支持多用戶認證
##sec=ntlmssp            認證方式爲標準smb認證方式

測試:



發佈了67 篇原創文章 · 獲贊 2 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章