操作系统:Centos7 Windows 10
硬件设备:虚拟机
某院系构建一台资源共享服务器,为本院系网络班和云计算班的的计算机提供文件共享服务,客户端计算机采用用户隔离的方式访问服务器上的资源,实现Windows和Linux资源共享。要求网络班的资料存放在samba服务器(smb.dingli.com)的/mnt/network目录中,云计算班的资料存放在samba服务器的/mnt/cloud目录中。
[root@servera ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 300M 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 17.7G 0 part /
sr0 11:0 1 9.5G 0 rom /run/media/root/CentOS 7 x86_64
sr1 11:1 1 1024M 0 rom
[root@servera ~]# mkdir /mnt/cdrom
[root@servera ~]# mount /dev/cdrom /mnt/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
[root@servera ~]# rm -rf /etc/yum.repos.d/*
[root@servera ~]# vim /etc/yum.repos.d/local.repo
[root@servera ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
local | 3.6 kB 00:00
(1/4): local/group_gz | 153 kB 00:00
(2/4): local/primary_db | 6.1 MB 00:00
(3/4): local/filelists_db | 7.2 MB 00:00
(4/4): local/other_db | 2.6 MB 00:00
Metadata Cache Created
mkdir -p /mnt/network
mkdir -p /mnt/cloud
编辑Samba的主配置文件,通常是/etc/samba/smb.conf。在文件末尾添加以下内容,以定义两个共享目录及其权限:
vim /etc/samba/smb.conf
[network]
comment = Network Class Share
path = /mnt/network
browseable = yes
writable = yes
create mask = 0664
directory mask = 0775
force group = network_class
valid users = @network_class
force user = nobody
[cloud]
comment = Cloud Computing Class Share
path = /mnt/cloud
browseable = yes
writable = yes
create mask = 0664
directory mask = 0775
force group = cloud_class
valid users = @cloud_class
force user = nobody
为每个班级创建一个用户组,并为每个用户分配到相应的组中。假设网络班的用户组为network_class,云计算班的用户组为cloud_class。
groupadd network_class
groupadd cloud_class
useradd -m user1 -g network_class
useradd -m user2 -g cloud_class
passwd user1
passwd user2
chown -R root:network_class /mnt/network
chmod -R 2775 /mnt/network
chown -R root:cloud_class /mnt/cloud
chmod -R 2775 /mnt/cloud
smbpasswd -a user1
smbpasswd -a user2
systemctl restart smb.service
setenforce 0
systemctl stop firewalld.service
systemctl status smb.service
现在,网络班的用户(如user1)应该只能访问network共享,而云计算班的用户(如user2)只能访问cloud共享。在Windows客户端上,用户可以通过文件浏览器输入smb://smb.dingli.com/network或smb://smb.dingli.com/cloud来访问相应的共享资源,同时输入各自的用户名和密码进行身份验证。
服务器IP