题目要求:在 server0 上配置 SAMBA 服务
- l 您的 samba 服务器必须是 STAFF 工作组的一个成员
- l 只有网段 172.25.0.0/16 内的客户端可以访问 /common 共享
- l common 必须是可以浏览的
- l 用户 floyd 必须能够读取共享中的内容,如果需要的话,验证密码是 flectrag
知识点小贴士:
Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成。SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。SMB协议是客户机/服务器型协议,客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源。通过设置“NetBIOS over TCP/IP”使得Samba不但能与局域网络主机分享资源,还能与全世界的电脑分享资源。
解题步骤:
(1)安装samba, samba-client
<code>[root@server0 ~]# yum install -y samba samba-client/<code>
(2)enable 服务,使其开机自启动。
<code>[root@server0 yum.repos.d]# systemctl enable smb.service nmb.service
ln -s '/usr/lib/systemd/system/smb.service' '/etc/systemd/system/multi-user.target.wants/smb.service'
ln -s '/usr/lib/systemd/system/nmb.service' '/etc/systemd/system/multi-user.target.wants/nmb.service'/<code>
(3)由于是网络服务,防火墙需要放行samba服务,然后重新加载防火墙。
<code>[root@server0 yum.repos.d]# firewall-cmd --add-service=samba --permanent
success
[root@server0 yum.repos.d]# firewall-cmd --reload
Success/<code>
(4)检查STAFF组是否存在。如果不存在则需要创建。
<code>[root@server0 yum.repos.d]# gerep STAFF /etc/group
bash: gerep: command not found...
Similar command is: 'egrep'/<code>
注释:在/etc/group中没有查到,说明组不存在。
(5)创建一个系统层面的组。
<code>[root@server0 yum.repos.d]# groupadd -r STAFF/<code>
注释:参数 -r, --system 代表 create a system account
(6)创建用户rob
检查用户floyd是否存在。
用户不存在,那么需要新创建用户,在创建floyd时一定要检查desktop0上是否已经存在用户floyd、,如存在,那么需要对齐用户的uid, 不然会被扣分。
<code>[root@server0 yum.repos.d]# id STAFF
id: STAFF: no such user
[root@server0 yum.repos.d]# useradd floyd -s /sbin/nologin/<code>
创建用户,并对齐用户id
将用户floyd加入STAFF组中。
<code>[root@server0 yum.repos.d]# useradd floyd -s /sbin/nologin [root@server0 yum.repos.d]# usermod -G STAFF floyd/<code>
注释:-G, --groups GROUPS 表示 new list of supplementary GROUPS,这一步也可以不做,但是在实践中最好是要做的,这样让设置更加的完整。
(7)创建目录
<code>[root@server0 yum.repos.d]# mkdir /common/<code>
(8)将共享的文件夹所属组改为STAFF
<code>[root@server0 yum.repos.d]# chown :STAFF -R /common//<code>
注释:
-R, --recursive 表示 operate on files and directories recursively,即处理指定目录以及其子目录下的所有文件
(9)改变目录的权限
<code>[root@server0 yum.repos.d]# chmod 2775 /common//<code>
注释:这里设置了沾滞位的权限,SUID对应八进制数字“4”、SGID对应八进制数字“2”:如使用“chmod 4755”设置SUID权限,使用“chmod 2755”设置SGID权限,使用“chmod 6755”同时设置SUID和SGID权限
(10)设置目录的访问控制列表
<code>[root@server0 yum.repos.d]# setfacl -m floyd:rX /common//<code>
注释:因为是对目录设置,所有这里用了大写的X,如果是对文件设置那么需要用x
-m, --modify=acl 表示 modify the current ACL(s) of file(s)
(11)修改SELinux的上下文标签
<code>[root@server0 yum.repos.d]# semanage fcontext -a -t samba_share_t '/common(/.*)?'/<code>
注释:'/common(/.*)?' 不要忘记放在单引号里面。如果记不住(/.*)?, 那么可以执行命令semanage fcontext -l ,就会列出很多,可以从中复制一个。
检查是否设置成功
<code>[root@server0 yum.repos.d]# semanage fcontext -l | grep common
/common(/.*)? /<code>
生效安全上下文
<code>[root@server0 yum.repos.d]# restorecon -vFR /common/
restorecon reset /common context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0/<code>
注释:
-F Force reset of context 强制重设上下文
-R recursively 递归操作
-v verbose 显示修改过程
需要使用restorecon 命令将设置好的SELinux 安全上下文立即生效。在使用restorecon 命令时,可以加上-Rv 参数对指定的目录进行递归操作,以及显示SELinux 安全上下文的修改程。
(12)修改samba配置
<code>[root@server0 yum.repos.d]# vim /etc/samba/smb.conf/<code>
查找并修改workgroup
滚动到最后,找到如下Share Definitions部分,然后添加如下设置。
<code>[common]
comment = share to floyd
path = /common
browseable = yes
writable = no
hosts allow=172.25.0. .example.com/<code>
注释:
[common] 分享时对外可见的目录名称,不一定实际存在
comment = share to floyd 描述,可以不加这句,没影响
path = /common 本地对外共享的实际路径
browseable = yes
writable = no
hosts allow=172.25.0. .example.com
题目要求只有example.com域内的客户端可以访问common共享,注意172.25.0. 和 .example.com之间需要空格隔开。且172.25.0. 后面有一个点.example.com前面有一个点
(13)重启服务
<code>[root@server0 yum.repos.d]# systemctl restart smb nmb/<code>
(14)根据题目要求,创建samba用户floyd密码为flectrag
<code>[root@server0 yum.repos.d]# smbpasswd -a floyd
New SMB password:
Retype new SMB password:
Added user floyd./<code>
本题所有设置已经完成,下面去desktop0上进行验证。
(1)在desktop0上安装samba-client,验证需要安装samba-client。
<code>[root@desktop0 ~]# yum install -y samba-client/<code>
(2)验证是否可以看到server0上共享的目录
<code>[root@desktop0 ~]# smbclient -L //server0 -U rob/<code>
可以看到server0上配置的共享,说明配置成功。
<code> [root@desktop0 ~]# yum -y install samba-client
Loaded plugins: langpacks
Package samba-client-4.1.1-31.el7.x86_64 already installed and latest version
Nothing to do/<code>
<code>[root@desktop0 ~]# smbclient -L //server0 -U floyd
Enter floyd's password:
Domain=[STAFF] OS=[Unix] Server=[Samba 4.1.1]
Sharename Type Comment
--------- ---- -------
common Disk share to floyd
IPC$ IPC IPC Service (Samba Server Version 4.1.1)
floyd Disk Home Directories
Domain=[STAFF] OS=[Unix] Server=[Samba 4.1.1]
Server Comment
--------- -------
SERVER0 Samba Server Version 4.1.1
Workgroup Master
--------- -------
STAFF SERVER0
[root@desktop0 ~]#/<code>
常见错误解决:linux报错:yum 命令报错 “ There are no enabled repos ” —— yum repolist 为 0
<code>[root@server0 ~]# yum install -y samba samba-client
Loaded plugins: langpacks
There are no enabled repos.
Run "yum repolist all" to see the repos you have.
You can enable repos with yum-config-manager --enable <repo>
[root@server0 ~]# yum repolist all
Loaded plugins: langpacks
repolist: 0/<repo>/<code>
(1)yum list可以查出数来,证明ISO系统镜像是关联了的且挂载成功:
(2)yum repolist显示仓库的时候是0
<code>[root@server0 ~]# yum repolist
Loaded plugins: langpacks
repolist: 0/<code>
(3)总结原因:问题应该出在了.repo文件上了。
<code>[root@server0 ~]# cd /etc/yum.repos.d/
[root@server0 yum.repos.d]# ll
total 0
[root@server0 yum.repos.d]#/<code>
无*.repo文件
(4)创建repo文件,可以从desktop0上复制,创建一个文件:
<code>[root@server0 yum.repos.d]# vim /etc/yum.repos.d/classroom.example.com_content_rhel7.0_x86_64_dvd.repo/<code>
<code>
[classroom.example.com_content_rhel7.0_x86_64_dvd]
name=added from: http://classroom.example.com/content/rhel7.0/x86_64/dvd
baseurl=http://classroom.example.com/content/rhel7.0/x86_64/dvd
enabled=1/<code>
(5)再次执行yum repolist all命令:
<code>[root@server0 yum.repos.d]# yum repolist all
Loaded plugins: langpacks
classroom.example.com_content_rhel7.0_x86_64_dvd | 4.1 kB 00:00
(1/2): classroom.example.com_content_rhel7.0_x86_6 | 134 kB 00:00
(2/2): classroom.example.com_content_rhel7.0_x86_6 | 3.4 MB 00:00
repo id repo nam status
classroom.example.com_content_rhel7.0_x86_64_dvd added fr enabled: 4,305
repolist: 4,305/<code>
(6)成功安装软件包:
<code>[root@server0 yum.repos.d]# yum -y install samba samba-client
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package samba.x86_64 0:4.1.1-31.el7 will be installed
---> Package samba-client.x86_64 0:4.1.1-31.el7 will be installed
--> Finished Dependency Resolution/<code>
閱讀更多 神小威 的文章