问题描述:
根据公司的信息化建设要求,需要在局域网内部搭建一台文件服务器,便于对数据的集中管理和备份。考虑到服务器的运行效率及稳定、安全性,选择在RHEL5操作系统中构建Samba服务器以提供文件资源共享服务。
1.将服务器192.168.1.1的/usr/src目录共享,共享名设为tools;将/usr/lib64目录共享,共享名设为rhel5lib。
2.tools共享允许Windows或Linux客户机匿名浏览及访问,但只有读取权限,禁止上传、删除、重命名等写入操作。
3.rhel5lib共享也允许匿名访问,但是从客户机浏览时将不可见(隐藏共享目录),只有当用户知道此共享名称时才能够访问。
解决方案:
在192.168.1.1主机上搭建samba服务器,添加两台客户机,一台客户机RHEL5的ip地址为192.168.1.2,另外一台win7主机的ip为192.168.1.3,用客户端验证访问共享。
搭建过程:
[一]匿名用户访问共享
1,在服务器上查看smb服务是否安装
[root@localhost ~]# rpm -qi samba
package samba is not installed……未安装
2,安装samba服务相关软件
[root@localhost~]# yum install -y samba
…….
[root@localhost~]# yum install -y samba-client
…
3,配置samba服务
[root@localhost ~]# vim /etc/samba/smb.conf
修改
security = share
passdb backend = tdbsam
追加
[tools]
path = /usr/src
public = yes
readonly = yes
[rhel5lib]
path = /usr/lib64
public = yes
readonly = yes
browseable = no……不可浏览
"/etc/samba/smb.conf" 297L, 9838C 296,2-9 Bot
检查Samba配置的正确性、查看有效配置清单
[root@localhost Server]# testparm
……
4,启动samba服务
[root@localhost ~]# service smb restart
Shutting down SMB services: [ OK ]
Shutting down NMB services: [ OK ]
Starting SMB services: [ OK ]
Starting NMB services: [ OK ]
[root@localhost ~]# chkconfig smb on
[root@localhost ~]# chkconfig --list smb
smb 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5,在win7上验证
UNC路径访问192.168.1.1不可见rhel5lib
输入\\192.168.1.1\rhel5lib
在windows下做磁盘映射
6,在rhel客户机上访问samba服务,首先安装samba-client客户端
[root@localhost ~]# yum install -y samba-client
[root@localhost ~]# smbclient -L 192.168.1.1
查看服务端共享
Password: ……匿名用户访问无需输入密码,直接Enter进入
Domain=[MYGROUP] OS=[Unix] Server=[Samba3.0.33-3.39.el5_8]
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC Service (Samba Server Version3.0.33-3.39.el5_8)
tools Disk
[root@localhost ~]# smbclient //192.168.1.1/tools
Password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba3.0.33-3.39.el5_8]
Server not using user level security and no passwordsupplied.
smb: \>
smb: \> exit……退出共享
[root@localhost ~]# smbclient //192.168.1.1/rhel5lib
Password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.33-3.39.el5_8]
Server not using user level security and no passwordsupplied.
smb: \> mkdir test
NT_STATUS_MEDIA_WRITE_PROTECTED making remotedirectory \test
smb: \> ls test……无法写入
NT_STATUS_NO_SUCH_FILE listing \test
38751 blocks of size 524288. 31145 blocks available
smb: \> get libnfsidmap.so……可以下载资源
getting file \libnfsidmap.so of size 27408 aslibnfsidmap.so (669.1 kb/s) (average 669.1 kb/s)
[二]扩展:用户验证访问
1,建立共享用户账号
[root@localhost ~]# pdbedit -a bob
new password:
retype new password:
………………………..
………………
2,修改配置文件
修改全局配置
security = user……启用账户验证
passdb backend = tdbsam
修改自定义配置
[tools]
path =/usr/src
public= no……关闭匿名共享
validlist = bob,lili,sunny……账户列表
writelist = bob……允许写入权限列表
directory mask = 0760……创建目录默认权限
createmask = 0760……创建文件默认权限
deadtime = 10……10分钟无操作中断服务
[rhel5lib]
path =/usr/lib64
public= no
browseable = no……浏览不可见
validlist = bob,lili,sunny
writelist = bob
directory mask = 0760
createmask = 0760
deadtime = 10
307,2-9 99%
3,tools和lib默认权限是755,所以bob没有写入权限,需要定义acl规则
[root@localhost ~]# setfacl -m u:bob:rwx /usr/src/
[root@localhost ~]# setfacl -m u:bob:rwx /usr/lib64/
4,在win7上验证
5,在rhel客户端访问共享
[root@localhost ~]# smbclient -U bob//192.168.1.1/rhel5lib
Password:
Domain=[LOCALHOST] OS=[Unix] Server=[Samba3.0.33-3.39.el5_8]
smb: \> pwd
Current directory is \\192.168.1.1\rhel5lib\
smb: \> mkdir dir
smb: \> ls dir
dir D 0 Sun Mar 2 13:40:28 2014
38751 blocks of size 524288. 31145 blocks available
挂载共享
[root@localhost ~]# mount -o username=lili //192.168.1.1/tools /mnt/
Password:
[root@localhost~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 21G 3.0G 17G 16% /
/dev/sda1 104M 13M 86M 13% /boot
tmpfs 525M 0 525M 0% /dev/shm
/dev/hdc 4.3G 4.3G 0 100% /media/RHEL_5.9 x86_64 DVD
/dev/hdc 4.3G 4.3G 0 100% /misc/cd
//192.168.1.1/tools 21G 3.0G 17G 16% /mnt
[三]扩展:利用账户别名验证共享
1,修改smb配置文件,添加别名路径
[global]
#
workgroup = MYGROUP
serverstring = Samba Server Version %v
username map =/etc/samba/smbusers
; netbiosname = MYSERVER 309,2-9 99%
2,配置别名
[root@localhost ~]# vim /etc/samba/smbusers
# Unix_name = SMB_name1 SMB_name2 ...
root = administrator admin
nobody = guest pcguest smbguest
bob = stu01
lili = stu02
sunny = stu03
~
~
"/etc/samba/smbusers" 7L, 138C 6,1 All
3,在win7上验证
[四]扩展:访问地址限制
1,修改smb配置文件
[root@localhost~]# vim /etc/samba/smb.conf
[global]
#
workgroup = MYGROUP
server string = Samba Server Version %v
username map = /etc/samba/smbusers
hosts deny = 192.168.1.2
2,在rhel客户端访问共享
[root@localhost~]# mount -o username=lili //192.168.1.1/tools /mnt/
[root@localhost~]# smbclient -U lili //192.168.1.1/tools
Password:
Server not usinguser level security and no password supplied.
Receiving SMB:Server stopped responding
tree connectfailed: Call returned zero bytes (EOF)……访问失败
注意:1,匿名用户和账户验证只能开启其中一个
2,共享目录的权限最终权限是共享权限和本地权限的交集,必要时需要设置acl访问控制列表或将目录所有者改变
3,账户别名对全局生效因此必须在全局下配置:一个共享账号可以有多个别名中间用空格隔开
4,访问地址限制也是在全局下设置:
hostsallow = 客户端地址
hostsdeny = 客户端地址
客户端地址格式:
(1)以空格分隔多个地址
(2)主机名或IP地址
(3)网络地址192.168.10. 或者192.168.10.0/255.255.255.0
转载于:https://blog.51cto.com/1570880775/1369523