samba客户端配置及实例应用详解

1 Samba 客户端配置
1.1 Linux 客户端访问Samba 共享
linux 客户端访问服务器主要有两种方法
1)使用smbclient 命令
在 Linux 中,samba 客户端使用smbclint 这个程序来访问samba 服务器时,先要确保客户端已经安装了samba-client 这个rpm包。
smbclient 可以列出目标主机共享目录列表。
smbclient 命令格式:smbclient -L 目标IP 地址或主机名-U 登录用户名%密码
当我们查看主机的共享目录列表时,提示输入密码,这时候可以不输入密码,我们直接按回车,这样表示匿名登录,然后就会显示匿名用户可以看到的共享目录列表。smbclient -L 主机名 或者smbclient -L 目录IP
[root@rusky2 samba]# smbclient -L rusky2
Password:
Anonymous login successful
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.23c-2]

Sharename Type Comment
--------- ---- -------
homes Disk Home Directories
public Disk Public
sales Disk sales data
IPC$ IPC IPC Service (Samba Server)
Anonymous login successful
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.23c-2]

Server     Comment
--------- -------
RUSKY2  Samba Server

Workgroup Master
--------- -------
MYGROUP RUSKY2
如果想使用 samba 帐号相看samba 服务器端共享了什么目录,我们可以加上-U参数~,后面跟上用户名%密码。
smbclient -L 192.168.0.188 -U boss%boss
这样就显示了只有 boss 帐号才显示的tech 技术部共享目录。
注意:不同用户使用smblient 浏览的结果可能是不一样,这要根据服务器设置的访问控制权
限而定。
我们还可以在使用smbclient命令行共享访问模式浏览共享的资料。smbclient 命令行共享访问模式命令格式:
smbclient //目标IP 地址或主机名/共享目录-U 用户名%密码
2)使用mount 命令挂载共享目录
mount 命令挂载共享目录格式:
mount -t cifs //目标IP 地址或主机名/共享目录名称挂载点 -o username=用户名
[root@client ~]# mount -t cifs //192.168.0.188/tech /mnt/sambadata/ -o username=boss%boss
这表示挂载192.168.0.188主机上的共享目录tech 到/mnt/sambadata 目录下,cifs 就是samba 所使用的文件系统
1.2 Samba 的打印共享
默认情况下,samba 的打印服务是开放~所以我们只要把打印机安装好后客户端的用户就可
以使用打印机了。
1)设置global 配置项
修改 smb.conf 全局配置,开启打印共享功能
# If you want to automatically load your printer list rather
# than setting them up individually then you'll need this
load printers = yes
# you may wish to override the location of the printcap file
printcap name = /etc/printcap
# on SystemV system setting printcap name to lpstat should allow
# you to automatically obtain a printer list from the SystemV spool
# system
printcap name = lpstat
# It should not be necessary to specify the print system type unless
# it is non-standard. Currently supported print systems include:
# bsd, cups, sysv, plp, lprng, aix, hpux, qnx
printing = cups
# This option tells cups that the data has already been rasterized
cups options = raw
# NOTE: If you have a BSD-style print system there is no need to
# specifically define each individual printer
[printers]
comment = All Printers
path = /usr/spool/samba
browseable = yes
# Set public = yes to allow user 'guest account' to print
guest ok = no
writable = no
printable = yes
安装完打印机后必须重新启动samba 服务,否则客户端可能无法看到共享的打印机。如果设置只允许部分员工使用打印机,我们可以使用valid users、hosts allow 或hosts deny 字段来实现。

2 Samba 企业实战与应用
2.1 企业环境及需求
samba 服务器目录:
企业数据目录:/companydata
公共目录:/companydata/share
销售部目录:/companydata/sales
技术部:/companydata/tech
企业员工情况:
总经理:gm
销售部:销售部经理redking、员工sky、员工jane
技术部:技术部经理michael、员工bill、员工joy
搭建samba 文件服务器,建立公共共享目录,允许所有人访问,权限为只读,为销售部和技术部分别建立单独的目录,只可以总经理和相应部门员工访问,并且公司员工禁止访问非本部门的共享目录。这是个典型的企业文件服务器案例。
2.2 需求分析
对于建立公共目录 public 字段就可以实现匿名访问,员工只能访问本部门的共享目录,禁止访问非本部门的共享目录,我们可以通过设置目录共享字段“browseable = no”及字段“valid users”来实现其隐藏功能和相应的访问权限。这样设置不能很好得解决同一目录多种需求的权限设置,所以我们需要建立独立配置文件,为每个部门建立一个组后并为每个组建立配置文件来实现隔离用户权限会比较灵活~
2.3 解决方案
2.31 建立各部门专用共享目录
使用 mkdir 建立需求的共享目录以便分门别类的存储相应资料,授权:chmod -R 777  /company/
[root@rusky2 /]# cd companydata/
[root@rusky2 companydata]# ls -l
total 12
drwxrwxrwx 2 root root 4096 Jul 10 02:42 sales
drwxrwxrwx 2 root root 4096 Jul 16 20:27 share
drwxrwxrwx 2 root root 4096 Jul 16 20:27 tech
2.32添加samba 服务器描述及设置smbpasswd 文件
# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
workgroup = companydomain
# server string is the equivalent of the NT Description field
server string = Company Samba File Server
默认/etc/samba/目录下没有smbpasswd 文件,我们要先关闭samba 的tdbsam验证。
解决方法:在smb.conf 文件中注释掉passdb backend = tdbsam 一行,为了指定samba用户的验证我们加上这一条smb passwd file = /etc/samba/smbpasswd,然后保存退出。
; passdb backend = tdbsam
smb passwd file = /etc/samba/smbpasswd
2.33 添加用户和组
先建立销售部组 sales,技术部组tech,然后使用useradd 命令添加总经理帐号gm及各个员
工的帐号并加入相应的用户组。
[root@rusky2 samba]# pwd
/etc/samba
[root@rusky2 samba]# ls
gm.smb.conf lmhosts sales.smb.conf secrets.tdb smb.conf smbpasswd smbusers tech.smb.conf
2.34 配置smb.conf 文件
(1)建立单独配置文件
用户配置文件使用用户名命令,组配置文件使用组名命令。
[root@rusky2 samba]# ls
gm.smb.conf lmhosts sales.smb.conf secrets.tdb smb.conf smbpasswd smbusers tech.smb.conf
(2)设置主配置文件smb.conf
这里我们配置 smb.conf 主配置文件,在global中添加相应字段,确保samba 服务器的主配置文件可以调用独立的用户配置文件和组配置文件。
include = /etc/samba/%U.smb.conf 表示使samba服务器加载/etc/samba 目录下格式为“用户名.smb.conf”的配置文件。
include = /etc/samba/%G.smb.conf 表示使samba服务器加载/etc/samba 目录下格式为“组名.smb.conf”的配置文件。
# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
workgroup = companydomain
include = /etc/samba/%U.smb.conf
include = /etc/samba/%G.smb.conf
# server string is the equivalent of the NT Description field
server string = Company Samba File Server
设置共享目录/companydata/share
[public]
comment = Public data
path = /companydata/share
public = yes
(3)设置总经理gm 配置文件
vi /etc/samba/gm.smb.conf
# A publicly accessible directory, but read only, except for people in
# the "staff" group
[sales]
comment = sales data
path = /companydata/sales
writable = yes
valid users = gm
[tech]
comment = tech data
path = /companydata/tech
writable = yes
valid users = gm
(4)设置销售部组sales 配置文件
[sales]
comment = sales data
path = /companydata/sales
valid users = @sales.gm
writable = yes
(5)设置技术部组tech 配置文件
vi /etc/samba/tech.smb.conf
[tech]
comment = tech data
path = /companydata/tech
valid users = @tech.gm #表示允许tech用户组和gm访问tech目录。
writable = yes
(6)重启samba 服务
service smb restart
(7)测试
gm账号登录后可看到所有共享目录,其它人登录后只能看到所属部门下的共享目录,并且对public目录只有可读权限。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值