SMB(Server Message Block)通信协议是微软(Microsoft)和英特尔(Intel)在1987年制定的协议,主要是作为Microsoft网络的通讯协议。SMB 是在会话层(session layer)和表示层(presentation layer)以及小部分应用层(application layer)的协议。SMB使用了NetBIOS的应用程序接口 (Application Program Interface,简称API)。另外,它是一个开放性的协议,允许了协议扩展——使得它变得更大而且复杂;大约有65个最上层的作业,而每个作业都超过120个函数,甚至Windows NT也没有全部支持到,最近微软又把 SMB 改名为 CIFS(Common Internet File System),并且加入了许多新的特色。
服务端
shareserver:
yum install samba samba-common samba-client -y 安装smb服务
systemctl start smb 开启服务
firewall-cmd --list-all
systemctl stop firewalld.service 关闭防护墙
systemctl disable firewalld.service
useradd westos 添加用户
smbpasswd -a westos 添加smb用户密码
getenforce
setenforce 0 selinx开启到警告模式
pdbedit -L 列出smb用户
pdbedit -x student 删除student用户
首先我们的实验环境将先正对于在linux系统之间进行文件共享
先安装smb软件
[root@station network-scripts]# yum install samba samba-common samba-client -y
samba 提供samba服务;
samba-common 提供管理命令;
samba-client 提供测试服务
开启服务:
关闭火墙:
添加smb用户:
客户端:
client:
yum install samba-client -y 安装smb客户端
smbclient -L //172.25.254.129 匿名用户登陆
smbclient -L //172.25.254.129 -U westos smb下的westos用户信息
smbclient //172.25.254.129/westos -U westos westos用户登陆
mount -o username=westos,password=lee //172.25.254.129/westos /mnt
cd /mnt
touch file{1..10} 建立文件
用westos用户登录
服务端:
shareserver:
setenforce 1 强制模式
getsebool -a | grep samba 查看selinux管理的smb服务
setsebool -P samba_enable_home_dirs on 开启
vim /etc/samba/smb.conf
89 workgroup = WESTOS WESTOS为所域名
90 server string = Samba Server Version %v
91
92 ; netbios name = MYSERVER
93
94 ; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
95 ; hosts allow = 127. 192.168.12. 192.168.13.
96 hosts allow = 172.25.254.129 172.25.254.229 容许登陆IP
97 hosts deny = 172.25.254.229 禁止登陆IP
98 ; max protocol = SMB2
共享自己的目录:
mkdir /westos
touch /westos/file{1..10}
vim /etc/samba/smb.conf
322 [linux] 客户能看到的共享目录名称
323 comment = westos dir share 目录说明
324 path = /westos 路径
325
326 [mnt] 客户能看到的共享系统目录名称
327 comment = mnt directory 目录说明
328 path = /mnt 路径
编辑文件:
systemctl restart smb.service #重启smb服务
semanage fcontext -a -t samba_share_t '/westos(/.*)?' #修改安全上下文
restorecon -RvvF /westos/
客户端:
smbclient //172.25.254.119/linux -U westos 用westos的smb用户登录
ls 查看共享目录
getsebool -a | grep samba
setsebool -P samba_export_all_ro on #开启对共享系统文件可读
smbclient //172.25.254.119/etc -U westos
ls
服务端:
对登录用权限的设定:
usermod -G student westos
id student 查看student的 id
chmod 777 /westos 更改、westos的权限
smbpasswd -a student 设置student用户的smb密码
vim /etc/samba/smb.conf
124 security = user
125 passdb backend = tdbsam
126 map to guest = bad user #匿名用户访问前提
322 [linux]
323 comment = westos dir share
324 path = /westos
325 writable = yes 可写
326 ; write list = @westos 组成员可写
327 ; valid users = +student 组成员可访问
328 browseable = yes 容许不隐藏
329 ; admin users = student 超级用户访问目录
330 guest ok = yes 可以匿名用户访问
smbclient //172.25.254.129/linux -U westos
smbclient //172.25.254.129/linux -U student
smbclient -L //172.25.254.129/linux -U westos
smbclient //172.25.254.129/linux
ls 列出
!ls 列出未访问前的家目录
put anaconda-ks.cfg 上传
rm anaconda-ks.cfg 删除
@ + 组成员的权限设定: