目录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)完成后能够进行写入了