|NO.Z.00030|——————————|^^ 部署 ^^|——|Linux&Samba服务.V03|——|Samba服务|
一、samba部署与实验
### --- 部署samba服务
~~~ 注:先关闭服务器和客户机上的防火墙和SElinux
~~~ 部署流程:
~~~ 服务端安装samba
[root@server21 ~]# yum -y install samba
### --- 确认客户端和相关命令软件包是否安装(默认是安装的)
[root@server22 ~]# rpm -q samba-client
samba-client-3.6.23-33.el6.x86_64
[root@server22 ~]# rpm -q samba-common
samba-common-3.6.23-33.el6.x86_64
### --- 创建共享区域
~~~ 备份主配置文件
~~~ 创建独立的共享区间(仿照模板编写)
### --- 启动smb服务并查看默认共享区域
[root@server21 ~]# service smb start
[root@server22 ~]# smbclient -U lisi -L //20.20.20.21
二、本地验证(登录/上传/下载)
### --- 本地验证(登录/上传/下载)
[root@server21 ~]# vim /etc/samba/smb.conf
~~~ 修改配置文件(添加自定义共享)
[atyanqi] // 共享名称
comment = share dir // 描述
path = /atyanqi // 共享具体目录
public = yes // 匿名可以访问吗,可以
writable = yes //
browseable = yes // 是否可见
; write list = +staff // 是否允许打印,注释掉;分号也是一个常见注释
### --- 创建共享目录并给定相应权限
[root@server21 ~]# mkdir /atyanqi
[root@server21 ~]# chmod 777 /atyanqi/ // 最好使用ACL权限
### --- 测试配置文件并重启服务
[root@server21 ~]# testparm
[root@server21 ~]# service smb restart
### --- 首先,创建linux用户
[root@server21 ~]# useradd -s /sbin/nologin zhangsan
[root@server21 ~]# passwd zhangsan // 不需要创建系统密码
### --- 转换为samba用户
[root@server21 ~]# pdbedit -a zhangsan
### --- 客户端查看共享文件夹并登录测试
smbcient -U zhangsan -L IP地址
smbclient -U zhangsan // IP地址/共享名
[root@server22 ~]# smbclient -U zhangsan -L //20.20.20.21
Enter zhangsan's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-33.el6]
Sharename Type Comment
--------- ---- -------
atyanqi Disk share dir
IPC$ IPC IPC Service (Samba Server Version 3.6.23-33.el6)
zhangsan Disk Home Directories
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-33.el6]
~~~ 注:由于未设置上传文件的默认权限,指定用户上传的文件只有自己能修改和覆盖。
[root@server22 ~]# smbclient -U lisi //20.20.20.21/lisi
Enter lisi's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-33.el6]
smb: \> ? // 调用帮助列表
三、访问控制—通过配置限制
### --- 访问控制—通过配置限制
~~~ 注:前提条件是指定目录权限给到最大,通过修改配置文件来实现实验结果
[root@server21 ~]# vim /etc/samba/smb.conf
[atyanqi]
comment = share dir
path = /atyanqi
public = yes
writable = yes
browseable = yes
valid users = zhangsan // 仅允许部分用户访问共享局域
[root@server21 ~]# service smb restart
### --- 验证:
[root@server22 ~]# smbclient -U lisi //20.20.20.21/atyanqi //李四是被拒绝的。因为李四没有写入到 vaild users
Enter lisi's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-33.el6]
tree connect failed: NT_STATUS_ACCESS_DENIED
[root@server22 ~]# smbclient -U zhangsan //20.20.20.21/atyanqi //张三是可以正常登入的
Enter zhangsan's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-33.el6]
smb: \>
### --- 部分用户登录samba服务器
~~~ 修改/etc/samba/smb.conf中自定义的共享区域
~~~ 添加:设置合法用户列表
valid users = 用户,@组(多个逗号分隔)
### --- 部分用户对共享区域有写权限
~~~ 修改/etc/samba/smb.conf中自定义的共享区域
~~~ 添加:开启只读,设置可写列表
[root@server21 ~]# vim /etc/samba/smb.conf
[atyanqi]
comment = share dir
path = /atyanqi
public = yes
writable = yes
browseable = yes
; valid users = zhangsan
read only = yes // 开启只读
write list = lisi // 允许那个用户写入
[root@server21 ~]# service smb restart
### --- 验证:
[root@server22 ~]# smbclient -U lisi //20.20.20.21/atyanqi // 李四是可以登入并写入文件的,并且是可以覆盖的。
Enter lisi's password:
smb: \> put anaconda-ks.cfg
putting file anaconda-ks.cfg as \anaconda-ks.cfg (19.7 kb/s) (average 19.7 kb/s)
smb: \> ls
anaconda-ks.cfg A 1112 Thu Feb 4 11:30:59 2021
[root@server22 ~]# smbclient -U zhangsan //20.20.20.21/atyanqi // 张三是可以登入的,但不可以写入
Enter zhangsan's password:
smb: \> put anaconda-ks.cfg
NT_STATUS_ACCESS_DENIED opening remote file \anaconda-ks.cfg
### --- 设置上传文件的默认权限
[root@server21 ~]# ll /atyanqi/ // 查看上传上来的文件权限是744,是不合理的,可执行文件
total 4
-rwxr--r-- 1 lisi lisi 1112 Feb 4 11:30 anaconda-ks.cfg
~~~ mask是默认权限
~~~ umask是掩码权限;掩码是022才是644权限。
create mask // 文件的默认权限
directory mask // 目录的默认权限
[atyanqi]
comment = share dir
path = /atyanqi
public = yes
writable = yes
browseable = yes
; valid users = zhangsan
read only = yes
write list = lisi
create mask = 644 // 设置上传文件的权限为644
[root@server21 ~]# service smb restart
### --- 验证:
[root@server22 ~]# smbclient -U lisi //20.20.20.21/atyanqi
Enter lisi's password:
smb: \> put install.log
.. DR 0 Thu Feb 4 11:13:52 2021
install.log 9615 Thu Feb 4 11:36:26 2021
[root@server21 ~]# service smb restart
Shutting down SMB services: [ OK ]
Starting SMB services: [ OK ]
[root@server21 ~]# ll /atyanqi/
total 16
-rwxr--r-- 1 lisi lisi 1112 Feb 4 11:30 anaconda-ks.cfg // 没有修改文件权限的文件上传后发生变化时744
-rw-r--r-- 1 lisi lisi 9615 Feb 4 11:36 install.log // 设置上传文件的权限为644,说明正确
四、用户别名(虚拟用户)
### --- 用户别名(虚拟用户)
### --- 添加别名(/etc/samba/smbusers)
[root@server21 ~]# vim /etc/samba/smbusers
~~~ 添加:
root = administrator admin
nobody = guest pcguest smbguest
zhangsan = zs // 设置zhangsan的别名为zs
### --- 启用别名(修改注配置文件)
[root@server21 ~]# vim /etc/samba/smb.conf
~~~ 添加:
[global] // 最好写在global列表里
workgroup = MYGROUP
server string = Samba Server Version %v
username map = /etc/samba/smbusers // 设置让smb.conf主配置文件调用别名
[root@server21 ~]# service smb restart
### --- 测试:
[root@server22 ~]# smbclient -U zs //20.20.20.21/atyanqi // 使用zhangsan的别名zs登录成功,说明没有问题
Enter zs's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-33.el6]
smb: \>
[root@server22 ~]# smbclient -U ls //20.20.20.21/atyanqi // lisi的别名没有设置,所以会登录失败。
Enter ls's password:
session setup failed: NT_STATUS_LOGON_FAILURE
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
分类:
cdv007-network
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通