目錄html
(1)定義python
SMB (server message block):是一種用來訪問網絡中文件、打印機和其餘共享網絡資源的應用層通訊協議。主要功能是使網絡上的機器可以共享計算機文件、打印機、串行端口和通信等資源。提供經認證的進程間通訊機制,主要運行在windows系統下ios
(2)特性程序員
(3)歷史windows
SMB / CIFS / SMB1
CIFS (Common Internet File System):SMB2以前的SMB協議。centos
SMB 2.0
2006年,Microsoft 隨着 Windows Vista 的發佈 引入了新的SMB版本 (SMB 2.0 or SMB2)安全
SMB 2.1
SMB 2.1, 隨 Windows 7 和 Server 2008 R2 引入, 主要是經過引入新的機會鎖機制來提高性能。網絡
SMB 3.0
SMB 3.0 (previously named SMB 2.2) 在Windows 8 和 Windows Server 2012 中引入,帶來幾項重要的變化:
(1)the SMB Direct Protocol (SMB over remote direct memory access [RDMA])
(2)SMB Multichannel (multiple connections per SMB session)
(3)SMB Transparent Failoversession
SMB 3.0.2
隨 Windows 8.1 和 Windows Server 2012 R2引入。在這些版本和之後的版本中,能夠選擇性地禁用較早的SMB版本1,以提升安全性。less
SMB 3.1.1
隨 Windows 10 和 Windows Server 2016 引入。這個版本除了SMB3中添加的AES 128 CCM 加密以外,還支持AES 128 GCM 加密,並使用SHA-512散列實現預認證完整性檢查。在使用SMB2.x 以上版本的客戶端進行鏈接時,SMB 3.1.1還強制要求進行安全協商。
(1)定義
Samba 實現了 SMB 協議,是適用於 Linux 和 Unix 的標準 Windows 互操做性程序套件。Samba 是免費軟件,遵循 GNU General Public License(通用公共許可證)。提供安全、穩定、快速的文件和打印服務 。
(2)官方描述
Samba is the standard Windows interoperability suite of programs for Linux and Unix.
Samba is Free Software licensed under the GNU General Public License, the Samba project is a member of the Software Freedom Conservancy.
Since 1992, Samba has provided secure, stable and fast file and print services for all clients using the SMB/CIFS protocol.
Samba is an important component to seamlessly integrate Linux/Unix Servers and Desktops into Active Directory environments. It can function both as a domain controller or as a regular domain member.
(1)查看CentOS 版本
# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)
(2)經過 yum 安裝 Samba
# yum -y install samba samba-client samba-common
# rpm -qi samba Name : samba Epoch : 0 Version : 4.7.1 Release : 9.el7_5 Architecture: x86_64 ...
默認配置文件爲:/etc/samba/smb.conf
cat /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 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 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
示例文件爲:/etc/samba/smb.conf.example
cat /etc/samba/smb.conf.example #==== Global Settings ==== [global] # ---- Network-Related Options ---- workgroup = MYGROUP server string = Samba Server Version %v ; netbios name = MYSERVER ; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24 ; hosts allow = 127. 192.168.12. 192.168.13. # ---- Logging Options ---- log file = /var/log/samba/log.%m max log size = 50 # ---- Standalone Server Options ---- security = user passdb backend = tdbsam # ---- Printing Options ---- load printers = yes cups options = raw #==== Share Definitions ==== [homes] comment = Home Directories browseable = no writable = yes ; valid users = %S ; valid users = MYDOMAIN\%S [printers] comment = All Printers path = /var/spool/samba browseable = no guest ok = no writable = no printable = yes ...
# vi /etc/samba/smb.conf [global] workgroup = WORKGROUP netbios name = 137 security = user map to guest = bad user [anshare] comment = test share file path = /samba/anshare # 這裏限定只能經過 andy 訪問 valid users = andy browseable = yes writeable = yes guest ok = yes [nobodyshare] comment = nobody share file path = /samba/share browseable = yes writeable = yes guest ok = yes
mkdir /samba/anshare mkdir /samba/share //容許 nobodyshare 匿名訪問,所以須要修改 share 的用戶組 chown -R nobody:nobody /samba/share
注:這裏的共享目錄可使用 Ceph 塊設備掛載的文件夾,關於如何使用塊設備,請參考 塊設備快速入門
// -d 指定用戶登入時的啓始目錄 # useradd -d /home/andy // 設置密碼 # passwd andy
# smbpasswd -a andy New SMB password: //這裏輸入aa Retype new SMB password: Added user andy.
注:smbpasswd 命令的經常使用方法
smbpasswd -a 增長用戶(要增長的用戶必須以是系統用戶) smbpasswd -d 凍結用戶,就是這個用戶不能在登陸了 smbpasswd -e 恢復用戶,解凍用戶,讓凍結的用戶能夠在使用 smbpasswd -x 刪除用戶
# systemctl stop firewalld # setenforce 0
# systemctl enable smb & systemctl enable nmb # systemctl restart smb & systemctl restart nmb
# smbclient -L localhost -U andy Enter WORKGROUP\andy's password: //這裏輸入aa Sharename Type Comment --------- ---- ------- anshare Disk test share file IPC$ IPC IPC Service (Samba 4.7.1) Reconnecting with SMB1 for workgroup listing. Server Comment --------- ------- Workgroup Master --------- ------- WORKGROUP DESKTOP-H5VOITT
(1)在Windows中訪問共享文件夾
\\192.168.0.137
(2)進入共享文件夾
(3)發現沒有權限寫入
懷疑是共享目錄的權限問題:
# ll /samba drwxr-xr-x. 2 root root 6 11月 6 17:51 anshare drwxr-xr-x. 2 root root 6 11月 6 17:51 share
修改文件夾權限:
chmod 777 anshare chmod 777 share
(4)新建文件而後在 Linux 查看
# ll /samba/anshare drwxr-xr-x. 2 andy andy 6 11月 6 17:55 asd -rwxr--r--. 1 andy andy 4 11月 6 17:56 asd.txt # ll /samba/share -rwxr--r--. 1 andy andy 6 11月 6 18:05 aaa.txt
若是須要得到最新的 samba ,須要本身編譯安裝 samba 源碼。
在 官網 下載最新的穩定版,這裏咱們下載 Samba 4.7.11。
先卸載以前經過 yum 安裝的 Samba:
# yum -y remove samba samba-client samba-common
yum -y install gcc perl python-devel libacl-devel openldap-devel pam-devel
./configure
make
make install
軟件的默認安裝目錄
# pwd /usr/local/samba
執行 samba -V 查看版本
# /usr/local/samba/sbin/samba -V Version 4.7.11
配置文件的全路徑爲:/usr/local/samba/etc/smb.conf
注意 smb.conf 默認是沒有的,須要手動建立,示例文件爲:samba-4.7.11/examples/smb.conf.default
cat smb.conf.default cp smb.conf.default /usr/local/samba/etc/smb.conf
能夠發現,配置文件的結構以下:
#==== Global Settings ==== [global] workgroup = MYGROUP server string = Samba Server server role = standalone server log file = /usr/local/samba/var/log.%m max log size = 50 dns proxy = no #==== Share Definitions ==== [homes] comment = Home Directories browseable = no writable = yes ;[netlogon] ;[Profiles] [printers] comment = All Printers path = /usr/spool/samba browseable = no guest ok = no writable = no printable = yes ;[tmp] ;[public] ;[fredsprn] ;[fredsdir] ;[pchome] ;[public] ;[myshare]
這段配置默認把用戶的家目錄共享。
vi /usr/local/samba/etc/smb.conf [global] workgroup = MYGROUP server string = Samba Server server role = standalone server log file = /usr/local/samba/var/log.%m max log size = 50 dns proxy = no [myshare] comment = mary's stuff path = /usr/somewhere/shared valid users = mary public = no writable = yes printable = no create mask = 0765
mkdir -p /usr/somewhere/shared
# useradd -d /home/mary -m mary # passwd mary
# /usr/local/samba/bin/smbpasswd -a mary New SMB password: //這裏輸入mm Retype new SMB password: Added user mary.
獲得 smb用戶名:mary,smb密碼:mm
systemctl stop firewalld
# /usr/local/samba/sbin/smbd # /usr/local/samba/sbin/nmbd
# /usr/local/samba/bin/smbclient -L localhost -U mary Enter MYGROUP\mary's password: Sharename Type Comment --------- ---- ------- myshare Disk mary's stuff IPC$ IPC IPC Service (Samba Server) Reconnecting with SMB1 for workgroup listing. Server Comment --------- ------- Workgroup Master --------- ------- MYGROUP SAMBA
(1)在Windows中訪問共享文件夾
\\192.168.0.137
(2)輸入 smb 用戶名和密碼
(3)肯定後能夠看到 myshare
(4)發現沒有權限寫入
(5)修改共享目錄權限
懷疑是共享目錄的權限問題:
# ll /usr/somewhere drwxr-xr-x. 2 root root 6 11月 6 10:54 shared
修改目錄權限:
# chmod 777 /usr/somewhere/shared/
(6)完成後能夠進行寫入了