linux文件服務之Samba

一、Samba   linux

         

Samba服務 vim

          Samba是在Linux和UNIX系統上實現SMB協議的一個免費軟件,由服務器及客戶端程序構成。SMB(Server Messages Block,信息服務塊)是一種在局域網上共享文件和打印機的一種通訊協議,它爲局域網內的不一樣計算機之間提供文件及打印機等資源的共享服務。SMB協議是客戶機/服務器型協議,客戶機經過該協議能夠訪問服務          器上的共享文件系統、打印機及其餘資源。經過設置「NetBIOS over TCP/IP」使得Samba不但能與局域網絡主機分享資源,還能與全世界的電腦分享資源。windows


做用:共享目錄(smb協議)緩存

軟件:samba 服務端, samba-client 客戶端 服務器

配置文件:/etc/samba/smb.conf 網絡

服務:smb, nmb tcp

端口:smb ---> 139/tcp,  445/tcp    提供文件共享功能ide

 nmb ---> 137/udp,  138/udp 提供解析計算機名稱測試

配置文件:/etc/samba/smb.confspa


全局配置


[global]

        workgroup = MYGROUP>>>設置工做組名稱

        server string = Samba Server Version %v>>>顯示samba軟件版本信息


interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24>>>samba服務監聽的IP地址


hosts allow = 127. 192.168.12. 192.168.13.>>>設置僅容許哪些主機可訪問

hosts deny = 192.168.12.  192.168.1.1/24>>>拒絕哪些主機可訪問

security = user>>> 基於用戶認證的訪問 

share>>> 匿名訪問

共享目錄配置


[共享名稱]

comment = >>> 描述信息

path = /bj>>> 指定目錄名稱

browseable = yes >>> 可下載文件

writable = yes >>> 可上傳文件

public = yes >>> 容許全部用戶訪問 

write list = user1>>> 僅容許user1可上傳文件 


示例: 


環境描述:

Linux    192.168.122.105Centos 7.2 文件共享服務器

Windows/Linux 客戶端 

需求:

經過samba軟件將本地的/caiwu目錄共享, 客戶端可經過martin用戶訪問,僅容許其下載文件  

1) 關閉SELinux, 防火牆 


[root@file-server ~]# setenforce 0

[root@file-server ~]# getenforce 

Permissive

[root@file-server ~]# vim /etc/sysconfig/selinux 


[root@file-server ~]# systemctl stop firewalld.service 

[root@file-server ~]# systemctl disable firewalld.service 

2) 安裝軟件  


[root@file-server ~]# yum install -y samba samba-client

3) 編輯配置文件,共享/caiwu目錄


[root@file-server ~]# mkdir /caiwu

[root@file-server ~]# touch /caiwu/{1..5}.mp3

[root@file-server ~]# vim /etc/samba/smb.conf 

        [caiwu]

        comment = It is a test

        path = /caiwu

        browseable = yes


4) 建立共享用戶 


[root@file-server ~]# useradd martin

[root@file-server ~]# smbpasswd -a martin

New SMB password:

Retype new SMB password:

Added user martin.


[root@file-server ~]# pdbedit -L>>> 查看共享用戶

martin:1001:

[root@file-server ~]# 



5) 啓動服務 


[root@file-server ~]# systemctl start smb

[root@file-server ~]# systemctl enable smb

 

[root@file-server ~]# ss -antp | grep smbd

LISTEN     0      50           *:139                      *:*                   users:(("smbd",pid=2804,fd=38))

LISTEN     0      50           *:445                      *:*                   users:(("smbd",pid=2804,fd=37))

LISTEN     0      50          :::139                     :::*                   users:(("smbd",pid=2804,fd=36))

LISTEN     0      50          :::445                     :::*                   users:(("smbd",pid=2804,fd=35))

6) 測試訪問 


Windows客戶端: 


\\192.168.122.105


取消用戶宿主目錄的共享

[root@file-server ~]# vim /etc/samba/smb.conf 


#[homes]

#       comment = Home Directories

#       browseable = no

#       writable = yes


[root@file-server ~]# systemctl restart smb

Linux客戶端:


[root@client ~]# yum install -y samba-client


[root@client ~]# smbclient //192.168.122.105/caiwu -U martin

配置容許martin用戶可上傳文件  


1) 編輯配置文件 


[root@file-server ~]# vim /etc/samba/smb.conf 

[caiwu]

...

writable = yes 

[root@file-server ~]# systemctl restart smb


2) 設置目錄的本地權限  


[root@file-server ~]# setfacl -m u:martin:rwx /caiwu/

示例: 


經過samba軟件將本地的/shichang目錄共享,容許martin用戶下載文件,容許admin用戶上傳文件  

1) 建立目錄,建立共享用戶 


[root@file-server ~]# mkdir /shichang

[root@file-server ~]# touch /shichang/{1..5}.jpg

[root@file-server ~]# 

[root@file-server ~]# useradd admin

[root@file-server ~]# smbpasswd -a admin

New SMB password:

Retype new SMB password:

Added user admin.

[root@file-server ~]# 

[root@file-server ~]# pdbedit -L

martin:1001:

admin:1002:

[root@file-server ~]# 



2) 編輯配置文件


[root@file-server ~]# vim /etc/samba/smb.conf 


[shichang]

    path = /shichang

    browseable = yes

    write list = admin


[root@file-server ~]# systemctl restart smb


[root@file-server ~]# chown admin /shichang/

[root@file-server ~]# ls -ldh /shichang/

drwxr-xr-x. 2 admin root 66 2月  21 12:00 /shichang/

[root@file-server ~]# 

3) 測試訪問 


清除windows的共享緩存 

net use * /del 

windows設置網絡映射驅動器訪問共享  

相關文章
相關標籤/搜索