题目:建立samba共享,共享目录为/data,要求:(描述完整的过程)
1)共享名为shared,工作组为magedu;
2)添加组develop,添加用户gentoo,centos和ubuntu,其中gentoo和centos以develop为附加组,ubuntu不属于develop组;密码均为用户名;
3)添加samba用户gentoo,centos和ubuntu,密码均为“mageedu”;
4)此samba共享shared仅允许develop组具有写权限,其他用户只能以只读方式访问;
5)此samba共享服务仅允许来自于192.168.0.0/16网络的主机访问;
搭建环境:
Samba服务器:192.168.10.101 (CentOS 7)
相关程序包:
Samba服务端程序包:samba
Samba客户端程序包:samba-client
搭建Samba详细过程:
1、创建共享目录/data
[[email protected] ~]# mkdir /data
2、创建系统用户和组
[[email protected] ~]# useradd gentoo # 创建用户gentoo [[email protected] ~]# useradd centos # 创建用户centos [[email protected] ~]# useradd ubuntu # 创建用户ubuntu [[email protected] ~]# echo ‘gentoo‘ | passwd --stdin gentoo # 为用户gentoo设置密码 [[email protected] ~]# echo ‘centos‘ | passwd --stdin centos # 为用户centos设置密码 [[email protected] ~]# echo ‘ubuntu‘ | passwd --stdin ubuntu # 为用户ubuntu设置密码 [[email protected] ~]# groupadd develop # 创建组develop [[email protected] ~]# usermod -aG develop gentoo # 添加用户gentoo到组develop [[email protected] ~]# usermod -aG develop centos # 添加用户centos到组develop
3、编辑Samba主配置文件/etc/samba/smb.conf,添加如下配置
[[email protected] ~]# vim /etc/samba/smb.conf [global] workgroup = magedu [shared] workgroup = magedu comment = data dir path = /data browseable = yes write list = @develop
4、检查语法错误
[[email protected] ~]# testparm [shared] comment = data dir path = /data hosts allow = 192.168. write list = @develop
5、为用户centos、gentoo、ubuntu设置samba服务的密码,密码均为“mageedu”
[[email protected] ~]# smbpasswd -a centos [[email protected] ~]# smbpasswd -a gentoo [[email protected] ~]# smbpasswd -a ubuntu 或者: [[email protected] ~]# pdbedit -a -u centos [[email protected] ~]# pdbedit -a -u gentoo [[email protected] ~]# pdbedit -a -u ubuntu [[email protected] ~]# pdbedit -L # 列出所有用户 centos:2004: gentoo:2003: ubuntu:2005:
6、设置组develop对文件系统的有写权限
[[email protected] ~]# setfacl -m g:develop:rwx /data
7、启动samba服务
[[email protected] ~]# systemctl start smb.service
8、使用samba客户端工具访问
(1)查看共享
[[email protected] ~]# smbclient -L //192.168.10.101/shared -U centos Enter centos‘s password: Domain=[MAGEDU] OS=[Windows 6.1] Server=[Samba 4.4.4] Sharename Type Comment --------- ---- ------- shared Disk data dir IPC$ IPC IPC Service (Samba Server Version 4.4.4) centos Disk Home Directories /home/centos Domain=[MAGEDU] OS=[Windows 6.1] Server=[Samba 4.4.4] Server Comment --------- ------- Workgroup Master --------- ------- SAMBA WWW
(2)交互式访问共享
#centos用户
[[email protected] ~]# smbclient //192.168.10.101/shared -U centos Enter centos‘s password: Domain=[MAGEDU] OS=[Windows 6.1] Server=[Samba 4.4.4] smb: \> mkdir centos # centos用户能上传文件,具有写权限 smb: \> ls . D 0 Sun Jun 11 10:28:46 2017 .. DR 0 Sun Jun 11 09:41:13 2017 centos D 0 Sun Jun 11 10:27:45 2017 52403200 blocks of size 1024. 46089400 blocks available
#gentoo用户
[[email protected] ~]# smbclient //192.168.10.101/shared -U gentoo Enter gentoo‘s password: Domain=[MAGEDU] OS=[Windows 6.1] Server=[Samba 4.4.4] smb: \> mkdir gentoo # gentoo用户能上传文件,具有写权限 smb: \> ls . D 0 Sun Jun 11 10:31:03 2017 .. DR 0 Sun Jun 11 09:41:13 2017 centos D 0 Sun Jun 11 10:27:45 2017 gentoo D 0 Sun Jun 11 10:31:03 2017 52403200 blocks of size 1024. 46089360 blocks available
#ubuntu用户
[[email protected] ~]# smbclient //192.168.10.101/shared -U ubuntu Enter ubuntu‘s password: Domain=[MAGEDU] OS=[Windows 6.1] Server=[Samba 4.4.4] smb: \> mkdir ubuntu # ubuntu用户不具有写权限 NT_STATUS_MEDIA_WRITE_PROTECTED making remote directory \ubuntu
(3)挂载访问共享
#centos用户
[[email protected] ~]# mkdir /centos [[email protected] ~]# mount -t cifs -o username=centos,password=magedu //192.168.10.101/shared /centos [[email protected] ~]# cd /centos [[email protected] centos]# ls centos gentoo [[email protected] centos]# touch centos-file [[email protected] centos]# ls centos centos-file gentoo # centos用户具有写权限
#gentoo用户
[[email protected] ~]# mkdir /gentoo [[email protected] ~]# mount -t cifs -o username=gentoo,password=magedu //192.168.10.101/shared /gentoo [[email protected] ~]# cd /gentoo [[email protected] gentoo]# ls centos centos-file gentoo [[email protected] gentoo]# touch gentoo-file [[email protected] gentoo]# ls centos centos-file gentoo gentoo-file # gentoo用户具有写权限
#ubuntu用户
[[email protected] ~]# mkdir /ubuntu [[email protected] ~]# mount -t cifs -o username=ubuntu,password=magedu //192.168.10.101/shared /ubuntu [[email protected] ~]# cd /ubuntu [[email protected] ubuntu]# ls centos centos-file gentoo gentoo-file [[email protected] ubuntu]# touch ubuntu-file touch: cannot touch ‘ubuntu-file’: Permission denied # ubuntu用户不具有写权限
时间: 2024-10-25 12:07:44