1、share服务器实例及详解
如果公司现在用一个工作组Workgroup需要添加samba服务器作为文件服务器,并发布共享目录/share,共享名为public,这个共享目录允许所有公司员工访问。
我们分析下,这个案例属于samba的基本配置,我们可以实用share安全级别模式,既允许所有员工访问,则需要为每个用户建立一个samba帐号,那么如果公司拥有大量用户呢?
1000个用户,100000个用户,一个个设置会非常滴麻烦,我们可以通过配置security=share来让所有用户登录时采用匿名帐户nobody访问,这样实现起来非常简单
1)修改samba主配置文件smb.conf
vi /etc/samba/smb.conf
(1).设置samba服务器工作组名为Workgroup
(2).添加samba服务器注释信息为"FileServer"
(3).设置samba安全级别为share模式,允许用户匿名访问
#======================= Global Settings =====================================
[global]
# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
workgroup = Workgroup
# server string is the equivalent of the NT Description field
server string = FileServer
username map = /etc/samba/smbusers
# Security mode. Defines in which mode Samba will operate. Possible
# values are share, user, server, domain and ads. Most people will want
# user level security. See the Samba-HOWTO-Collection for details.
security = share
(4).设置共享目录的共享名为public
(5).设置共享目录的绝对路径为/share
(6).最后我们设置允许匿名访问
# A publicly accessible directory, but read only, except for people in
# the "staff" group
[public]
comment = Public
path = /share
public = yes
writable = yes
printable = no
; write list = @staff
设置完smb.conf 后保存退出
2)重新加载配置
上面我们说过,Linux 为了使新配置生效,需要重新加载配置,可以使用restart 重新启动服务或者使用reload 重新加载配置
注意:
这里强调一下细节,重启samba 服务,虽然可以让配置生效,但是restart 是先关闭samba 服务,再开启服务,这样如果在公司网络运营中肯定会对客户端员工的访问造成影响,建议使用reload 命令重新加载配置文件使其生效,这样不需要中断服务就可以重新加载配置
[root@rusky2 samba]# service smb restart
Shutting down SMB services: [ OK ]
Shutting down NMB services: [ OK ]
Starting SMB services: [ OK ]
Starting NMB services: [ OK ]
[root@rusky2 samba]# service smb reload
Reloading smb.conf file: [ OK ]
samba 服务器通过以上设置,现在用户就可以不需要输入帐号和密码就可以直接登录samba服务器并访问public 共享目录
我们测试下,在/share 目录下建个文件试下:touch test
然后通过windonws访问samba服务器共享文件。

SAMBA安全模式share及user实例详解_服务器

2、user服务器实例及详解
上面的案例我们讲了 share 安全级别模式的samba 服务器,可以实现用户方便滴通过匿名方式访问,但是如果在我们samba 服务器上存在重要文件的目录,为了保证系统安全性及资料保密性,我们就必须对用户进行筛选,允许或禁止相应的用户访问指定滴目录,这里share 安全级别模式就不能满足我们这样的实际要求了。
实现用户身份验证的方法很多,我们可以将安全级别模式配置为user、server、domain 和ads,但是最常用的还是user安全级别模式,下面偶就来看下user这个安全级别模式的配置。
如果公司有多个部门,因工作需要,我们就会分门别类的建立相应部门的目录,并将销售部的资料存放在samba 服务器的/companydata/sales/目录下,集中管理,以便销售人员浏览,并且该目录只允许销售部员工访问。
我们分析下,在/companydata/sales/目录中存放有销售部的重要数据,为了保证其他部门无法查看其内容,我们需要将全局配置中security 设置为user安全级别,这样就启用了samba服务器的身份验证机制,然后在共享目录/companydata/sales 下设置valid users 字段,配置只允许销售部员工能够访问这个共享目录。
1)添加销售部用户和组并添加相应samba 帐号
使用 groupadd 命令添加sales 组,然后执行useradd 命令和passwd 命令添加销售部员工的帐号及密码:
添加系统组和用户,并为用户设置密码

[root@rusky2 share]# groupadd sales
[root@rusky2 share]# useradd -g sales sale01 
[root@rusky2 share]# useradd -g sales sale02
[root@rusky2 share]# passwd sale01
Changing password for user sale01.
New UNIX password: 
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.
[root@rusky2 share]# passwd sale02
Changing password for user sale02.
New UNIX password: 
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.

添加samba用户

[root@rusky2 share]# cd /etc/samba/
[root@rusky2 samba]# smbpasswd -a sale01
New SMB password:
Retype new SMB password:
Added user sale01.
[root@rusky2 samba]# smbpasswd -a sale02
New SMB password:
Retype new SMB password:
Added user sale02. 901127910309 8256

2)修改samba 主配置文件smb.conf
(1).设置user安全级别模式
# Security mode. Defines in which mode Samba will operate. Possible
# values are share, user, server, domain and ads. Most people will want
# user level security. See the Samba-HOWTO-Collection for details.
security = user
(2).设置销售部共享目录为sales
(3).指定共享目录为绝对路径为/companydata/sales,手动到根目录下创建该目录 mkdir -p /companydata/sales
(4).设置可以访问的用户为sales 组成员
# A publicly accessible directory, but read only, except for people in
# the "staff" group
[public]
  comment = Public
  path = /share
  public = yes
writable = yes
printable = no
; write list = @staff
[sales]
  #设置共享目录名为sales
  comment = sales data
  path=/companydata/sales
  #设置共享目录的绝对路径为:/companydata/sales
  valid users = @sales
  #设置只允许销售部sales组员可以访问
3)重新加载配置
上个案例讲过了,要让修改后的Linux 配置文件生效,我们就要重新加载配置。
[root@rusky2 samba]# service smb reload
Reloading smb.conf file: [ OK ]
任何用户登录可访问public目录,只sales组的用户输入用户名和密码之后可访问sales目录。

SAMBA安全模式share及user实例详解_unix_02