实验二
公司的IT部门有it1、it2两个成员,他们可以登录到自己部门的共享目录进行读写操作,上传的文件的权限为640,且只允许他们之间读取文件,但不可以修改对方的文件。
一、准备工作
1.创建用户it1、it2和用户组it,并将it1和it2加入到用户组it。
2.创建共享目录/it,将其权限属性置为777,并使用chcon -t samba_share_t /it命令修改其安全上下文(本实验仍然在SELinux开启的情况下进行测试)。
3.将用户it1、it2加入到samba服务器
[root@luffy ~]# smbpasswd -a it1
New SMB password:
Retype new SMB password:
Added user it1.
[root@luffy ~]# smbpasswd -a it2
New SMB password:
Retype new SMB password:
Added user it2.
二、配置共享
1. 在主配文件/etc/samba/smb.conf末尾添加以下内容:
|
1
2
3
4
5
6
7
8
9
|
[it]comment = it dept.path = /itbrowseable=yeswritable = yesvalid users = @it #指定允许访问的用户组为it,注意@符号create mask = 640 #指定新创建的文件的权限为640directory mask = 750 #指定新创建的文件夹的权限为750group = it #指定新创建的文件(夹)的用户组为it,这里没有@ |
配置修改完成后,重启samba服务,
[root@luffy ~]# service smb restart
2.客户端访问
[root@zoro ~]# smbclient //192.168.56.53/it -U user1
Enter user1's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.9-151.el6]
tree connect failed: NT_STATUS_ACCESS_DENIED
[root@zoro ~]# smbclient //192.168.56.53/it -U it1
Enter it1's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.9-151.el6]
smb: \> quit
[root@zoro ~]# smbclient //192.168.56.53/it -U it2
Enter it2's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.9-151.el6]
smb: \> ls
. D 0 Mon May 27 05:40:45 2013
.. DR 0 Mon May 27 05:40:45 2013
40317 blocks of size 262144. 31463 blocks available
smb: \> quit
从以上连接可以看出,只有属于it用户组的用户才有访问/it的权限。
