Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3448503
  • 博文数量: 349
  • 博客积分: 5771
  • 博客等级: 大校
  • 技术积分: 4193
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-06 11:52
个人简介

it

文章分类

全部博文(349)

文章存档

2019年(2)

2018年(2)

2017年(1)

2016年(2)

2015年(18)

2014年(36)

2013年(69)

2012年(100)

2011年(62)

2010年(57)

分类:

2010-06-28 08:02:35

smbd和nmbd使用的全部配置信息全都保存在smb.conf文件中。Smb.conf向smbd和nmbd两个守护进程说明输出什么,共享输出给 谁及如何进行输出以便共享。Smbd进程的作用是处理到来的SMB数据包,为使用该软件包的资源与Linux进行协商,nmbd进程使其它主机能浏览 Linux服务器。
[any material that should appear in print but not on the slide]
Page:5

  安装Samba

  第二张碟

  #rpm –qa samba

  #rpm –ivh samba-common-3.0.10-1.4E.i386.rpm

  #rpm –ivh samba-3.0.10-1.4E.i386.rpm

  #rpm –ivh samba-client-3.0.10-1.4E.i386.rpm

[any material that should appear in print but not on the slide]
Page:6

  Samba的默认配置

  文件/etc/samba/smb.conf是samba的配置文件。具体参数如下:

  workgroup=MYGROUP

  设置工作组名称

  server string=Samba Server

  设置samba服务器名称

  printcap name=/etc/printcap

  设置打印机配置文件路径

[any material that should appear in print but not on the slide]
Page:7

  load printers=yes

  允许共享打印机

  printing=cups

  设置打印系统类型

  log file=/var/log/samba/%m.log

  设置日志文件路径

  max log size=0

  不对日志文件做长度限制

[any material that should appear in print but not on the slide]
Page:8

  security=user

  设置user安全等级

  encrypt passwords=yes

  设置用户密码加密

  smb passwd file=/etc/samba/smbpasswd

  设置口令文件路径

  unix password sync=yes

  设置Samba用户账号和系统账号同步

[any material that should appear in print but not on the slide]
Page:9

  passwd program=/usr/bin/passwd %u

  设置本地口令程序

  [homes]

  comment=Home Directories

  browseable=no

  writable=yes

  valid users=%s

  create mode=0664

[any material that should appear in print but not on the slide]
Page:10

  directory mode=0775

  设置每个用户的主目录共享

  [printers]

  comment=All Printers

  path=/var/spool/samba

  browseable=no

  guest ok=no

  writable=no

[any material that should appear in print but not on the slide]
Page:11

  printable=yes

  设置全部打印机共享

[any material that should appear in print but not on the slide]
Page:12

  设置Samba密码文件

  当设置了 user的安全等级后,将由本地系统对访问Samba共享资源的用户进行认证。要进行认证,需要一个Samba的口令文件,该文件由smb passwd file参数指定,默认为/etc/samba/smbpasswd。初始情况下此文件并不存在,下面的任务是创建该文件。

  为了建立Samba的密码文件/etc/samba/smbpasswd,有两种方法:

  1、成批添加Samba账号。

  2、添加单个的Samba账号。

[any material that should appear in print but not on the slide]
Page:13

  建立Samba的密码文件

  将/etc/passwd里的用户都加到smbpasswd中。

  #cat /etc/passwd |mksmbpasswd.sh > /etc/samba/smbpasswd

  接下来用vi编辑smbpasswd文件,去掉一些无Shell的账户。

  然后使用smbpasswd命令为添加的账户设置Samba口令。

  #smbpasswd by

  注意:

  1、使用smbpasswd命令修改用户口令时,被修改的Samba账户的本地系统用户账号必须已经事先存在。

[any material that should appear in print but not on the slide]
Page:14

  2、使用带-a参数的smbpasswd命令添加单个samba账户并设置口令,且要求被添加的Samba账户的本地系统用户账号必须已经事先存在。

  3、若被添加的Samba账户的本地系统用户账号不存在,应该使用useradd命令进行添加。

[any material that should appear in print but not on the slide]
Page:15

  启动Samba服务器

  若用户对配置文件进行了修改,可以使用testparm命令检查配置文件的正确性。

  #testparm

  安装完Samba后,下一步就是启动了。Red Hat Linux默认Samba以独立运行方式启动,所以需要执行如下的步骤。

  #service smb start

  若希望Samba在下次计算机启动时自动启动,使用下面的命令:

  #ntsysv

  选中smb即可。

[any material that should appear in print but not on the slide]
Page:16

  测试Samba的默认配置

  在Windows环境下,打开网上邻居,查找Samba服务器,双击Samba服务器后进行用户验证,输入Samba用户和密码。

  接下来可以看到Samba服务器为该用户提供的共享。默认情况下只有登录用户的主目录共享和打印机共享。

  在共享资源上右击鼠标,在弹出的快捷菜单中选择“映射网络驱动器”。

[any material that should appear in print but not on the slide]
Page:17

  检查服务器所共享的资源

  用户可以在Linux下使用下面的命令检查服务器所共享的资源。

  #smbclient –L localhost

  用户可以在Linux下使用下面的命令查看Samba服务器资源被使用的情况。

  查看较详细的使用信息

  #smbstatus

  查看简要的使用信息

  #smbstatus -b

[any material that should appear in print but not on the slide]
Page:18

  smb.conf文件的结构

  Smb.conf文件采用了分节的结构,其基本格式和Windows中的.ini文件很类似。

  一般smb.conf文件由3个标准节和若干个用户自定义共享节所组成。

  [Global]:用于定义全局参数和缺省值

  [Homes]:用于定义用户的Home目录共享

  [Printers]:用于定义打印机共享

  [Userdefined_ShareName]:用户自定义共享(可有多个)

[any material that should appear in print but not on the slide]
Page:19

  Smb.conf文件的语法

  1、语法元素

  Smb.conf文件的语法元素

  #或;:注释

  [Name]:节名称

  \:续行符

  %:变量名前缀

  参数=值:一个配置选项,值可以有两种数据类型

  字符串:可以不用引号定界字符串

[any material that should appear in print but not on the slide]
Page:20

  1/0或yes/no或true/false

  2、变量(宏)

  Smb.conf文件常用的变量

  %S:当前服务名

  %P:当前服务的根路径

  %u:当前服务的用户名

  %g:给定%u的所在的主工作组名

  %H:给定的%u的宿主目录

[any material that should appear in print but not on the slide]
Page:21

  %v:Samba版本号

  %h:运行Samba的机器的主机名

  %m:客户机的NetBIOS名

  %L:服务器的NetBIOS名

  %T:当前的日期和时间

  3、Samba的安全等级

  Samba有四种安全等级,可以使用security参数进行指定。它们分别是:

  Share:用户不需要账户及密码即可登入Samba服务器。

[any material that should appear in print but not on the slide]
Page:22

  User:由提供服务的Samba服务器负责检查账户及密码(是Samba默认的安全等级)。

  Server:检查账户及密码的工作指定由另一台Windows NT/2000或Samba服务器负责。

  Domain:指定Windows NT/2000域控制服务器来验证用户的账户及密码。

[any material that should appear in print but not on the slide]
Page:23

  基本全局参数

  

参数
说明
举例
Netbios name
设置Samba的NetBIOS名字
Netbios name=byzjr
Workgroup
设置Samba要加入的工作组
Workgroup=workgroup
Server string
指定浏览列表里的机器描述
Server string= SmbSvr %v at %h
Client code page
设置客户字符编码页
Client code page=936
[any material that should appear in print but not on the slide]
Page:24

  安全全局参数

  

参数
说明
举例
Socket address
指定Samba监听的IP地址
Socket address=192.168.1.4
Admin user
设置管理员账号
Admin user=byzjr
Security
定义Samba的安全级别
Security=user
Encrypt passwords
用于指定是否使用加密口令
Encrypt passwords=yes
Smb passwd file
指定Samba口令文件的路径
Smb passwd file=/etc/samba/smbpasswd
Map to guest
设置Guest身份登录时用户名及密码不正确的处理方式
Map to guest=Never
Username map
指定SMB名字和UNIX名字映射文件的路径
Username map=/etc/samba/smbusers
Hosts allow
指定可以访问Samba的主机
Hosts allow=192.168.1.
Hosts deny
指定不可以访问Samba的主机
Hosts deny=192.168.2.
[any material that should appear in print but not on the slide]
Page:25

  日志全局参数

  

参数
说明
举例
Log file
指定日志文件的名称
Log file= /var/log/samba/%m.log
Max log size
指定日志文件的最大尺寸(KB)
Max log size= 100
[any material that should appear in print but not on the slide]
Page:26

  运行效率全局参数

  

参数
说明
举例
Change notify timeout
设置服务器周期性异常通知
Change notify timeout=90
Deadtime
客户端无操作多少分钟后服务器端中断连接
Deadtime=10
Getwd cache
是否使用Cache功能
Getwd cache=NO
keepalive
服务器每隔多少秒向客户端发送keepalive包用于确认客户端是否工作正常
Keepalive=60
Max open files
同一个客户端最多能打开的文件数目
Max open files=1000
Socket options
设置服务器和客户之间会话的Socket选项
Socket options=TCP_NODELAY
SO_RCVBUF=8192
SO_SNDBUF=8192
[any material that should appear in print but not on the slide]
Page:27

  设置共享资源参数

  Smb.conf文件常用的共享资源基本参数如下:

  

参数
说明
举例
Comment
指定对共享的描述
Comment=my share
path
指定共享服务的路径
Path=/tmp
[any material that should appear in print but not on the slide]
Page:28

  Smb.conf文件常用的共享资源访问控制参数如下:

  

参数
说明
举例
Writable
指定共享的路径是否可写
Writable=yes
Browseable
指定共享的路径是否可浏览(默认为可以)
Browseable=no
available
指定共享资源是否可用
Available=no
Read only
指定共享的路径是否为只读
Read only=yes
public
指定是否可以允许guest账户访问
Public=yes
Guest account
指定一般性客户的账号
Guest account=nobody
Guest ok
指定是否可以允许guest账户访问
Guest ok=yes
[any material that should appear in print but not on the slide]
Page:29

  

参数
说明
举例
Guest only
指定是否只允许guest账户访问
Guest only=yes
Read list
设置只读访问用户列表
Read list=tom
Write list
设置读写访问用户列表
Write list=tom
Valid users
指定允许使用服务的用户列表
Valid users=tom
Invalid users
指定不允许使用服务的用户列表
Invalid users=tom
[any material that should appear in print but not on the slide]
Page:30

  配置Samba文件共享举例

  1、修改Red Hat Linux默认的全局配置参数

  #vi /etc/samba/smb.conf

  修改工作组名称

  Workgroup=workgroup

  修改服务器的描述字符串

  Server string=Samba Server %v at %h

  修改允许访问Samba服务器的主机

  Hosts allow=192.168.1.

[any material that should appear in print but not on the slide]
Page:31

  添加client code page配置,使得客户可以支持简体中文的共享名

  Client code page=936

  2、使用符号链接组织本地共享资源

  可以使用符号链接组织本地共享资源,下面的操作步骤将系统的文档目录/usr/share/doc和本地匿名FTP站点目录/var/ftp组织在/var/samba目录下并进行共享。

  修改配置文件/etc/samba/smb.conf

  #vi /etc/samba/smb.conf

  添加Resource共享

[any material that should appear in print but not on the slide]
Page:32

  [Resource]

  Comment=Local Resource

  Path=/var/samba/resource

  Public=yes

  Writable=yes

  创建/var/samba/resource目录

  #mkdir /var/samba/resource

  进入/var/samba/resource

[any material that should appear in print but not on the slide]
Page:33

  #cd /var/samba/resource

  创建符号链接文件

  #ln –s /usr/share/doc doc

  #ln –s /var/ftp ftp

  3、为所有用户配置只读共享和读写共享

  为了配置对所有用户的只读共享,被共享的目录的本地文件系统上应该具有其他人的可读权限;为了配置对所有用户的读写共享,被共享的目录的本地文件系统上应该具有其他人的读写权限。

[any material that should appear in print but not on the slide]
Page:34

  修改配置文件/etc/samba/smb.conf

  #vi /etc/samba/smb.conf

  添加tmp的读写共享

  [tmp]

  Comment=Temporary file space

  Path=/tmp

  Read only=no

  Public=yes

[any material that should appear in print but not on the slide]
Page:35

  添加cdrom的只读共享

  [cdrom]

  Comment=CDROM

  Path=/mnt/cdrom

  Read only=yes

  Public=yes

[any material that should appear in print but not on the slide]
Page:36

  4、为指定用户或组配置Samba共享

  有时需要为指定的一个用户或多个用户提供共享资源;有时也需要为指定的组用户提供共享资源。

  为指定的用户配置Samba共享

  创建本地用户账号

  #useradd fred

  #passwd fred

  添加fred的Samba账号

  #smbpasswd –a fred

[any material that should appear in print but not on the slide]
Page:37

  创建本地共享目录

  #mkdir /var/samba/fred

  更改目录属主

  #chown fred.fred /var/samba/fred

  修改配置文件/etc/samba/smb.conf

  #vi /etc/samba/smb.conf

  为用户fred添加读写共享

  [fredsdir]

[any material that should appear in print but not on the slide]
Page:38

  Comment=Fred’s Service

  Path=/var/samba/fred

  Valid users=fred

  Public=no

  Writable=yes

  为指定的多个用户配置Samba共享

  创建本地用户账号

  #useradd tom

[any material that should appear in print but not on the slide]
Page:39

  #passwd tom

  #useradd ben

  #passwd ben

  添加Samba账号

  #smbpasswd –a tom

  #smbpasswd –a ben

  创建本地共享目录

  #mkdir /var/samba/tomben

[any material that should appear in print but not on the slide]
Page:40

  设置目录权限

  #chmod 707 /var/samba/tomben

  修改配置文件/etc/samba/smb.conf

  #vi /etc/samba/smb.conf

  为用户tom和ben添加读写共享

  [myshare]

  Comment=Tom’s and Ben’s Share

  Path=/var/samba/tomben

[any material that should appear in print but not on the slide]
Page:41

  Valid users=tom ben

  Public=no

  Writable=yes

  Create mask=0707

  为指定的组配置Samba共享

  创建本地用户账号和组账号

  #useradd staff

  #passwd staff

[any material that should appear in print but not on the slide]
Page:42

  #useradd –G staff user1

  #passwd user1

  #useradd –G staff user2

  #passwd user2

  添加Samba账号

  #smbpasswd –a user1

  #smbpasswd –a user2

  创建本地共享目录

[any material that should appear in print but not on the slide]
Page:43

  #mkdir /var/samba/staff

  设置属主和目录权限

  #chown staff.staff /var/samba/staff

  #chmod 770 /var/samba/staff

  修改配置文件/etc/samba/smb.conf

  #vi /etc/samba/smb.conf

  为staff组添加读写共享

  [staff]

[any material that should appear in print but not on the slide]
Page:44

  Comment=Public Staff

  Path=/var/samba/staff

  Public=yes

  Writable=yes

  Write list=@staff

  当所有共享配置结束并重新启动smb之后,在Windows的网上邻居中可以看到共享。

[any material that should appear in print but not on the slide]
Page:45

  重点:文件系统权限和共享权限:Samba服务器要将本地文件系统共享给Samba用户,这就涉及两种权限:本地文件系统权限和Samba权限。当Samba用户访问共享时,最终的权限将是这两种权限中最严格的权限。

  例如,如果在smb.conf中对用户设置了写权限,但用户对共享的Linux文件系统本身不具有写权限,结果就是用户对共享不具有写权限。

  注意:每当修改完配置文件/etc/samba/smb.conf之后,都要使用service smb restart命令重新启动Samba服务器使得配置生效。

[any material that should appear in print but not on the slide]
Page:46

  在Linux环境下访问Samba共享

  Linux系统中的/etc/hosts文件存放了TCP/IP主机名和IP地址的对应关系,即/etc/hosts是静态主机表。与之类似,Samba使用/etc/samba/lmhosts文件存放NetBIOS名与IP地址的静态映射表。

   当Linux主机作为Samba客户访问Windows的共享或其他Linux提供的Samba共享时,既可以使用IP地址访问,又可以使用 NetBIOS名访问。如果使用NetBIOS名访问共享,就需要在Samba客户上的/etc/samba/lmhosts文件中添加相应的记录。

[any material that should appear in print but not on the slide]
Page:47

  使用smbclient

  Samba提供了一个类似FTP客户程序的Samba客户程序smbclient,用以访问Windows共享或Linux提供的Samba共享。

  命令格式

  smbclient –L NetBIOS名或IP地址

  用于列表显示指定主机提供的共享

  smbclient //NetBIOS名或IP地址/共享名 -U 用户名

  用于访问指定主机的指定共享,-U用户名参数表示以指定的用户名的身份访问共享。

[any material that should appear in print but not on the slide]
Page:48

  注意:1、 当访问Windows共享时,smbclient命令的-U参数后所指定的用户名是所访问的Windows计算机中的用户账户,验证口令是Windows计算机中的用户账户的口令。

  2、当访问Linux提供的Samba共享时,smbclient命令的-U参数后所指定的用户名是所访问的Linux计算机中的Samba用户账户,验证口令是Samba用户账户的口令。

[any material that should appear in print but not on the slide]
Page:49

  使用smbclient命令查看并访问共享

  查看win计算机提供的共享

[any material that should appear in print but not on the slide]
Page:50

  以by用户身份访问win计算机的tools共享。接下来就可以像使用FTP客户的方法来使用smbclient。

[any material that should appear in print but not on the slide]
Page:51

  使用smbmount

  在Linux环境下使用共享资源的另一种方法是使用远程挂载方法将远程共享挂载到本地,这类似于在Windows环境下映射网络驱动器。使用远程挂载方法访问共享需要使用smbmount命令。

  创建挂载点目录

  #mkdir /mnt/smb/win

  将远程共享tools挂载到本地/mnt/smb/win目录

  #smbmount //win/tools /mnt/smb/win

[any material that should appear in print but not on the slide]
Page:52

  如果不能挂载,可以使用下面的命令:

  #smbmount //win/tools /mnt/smb/win –o username=by

  接下来就可以像使用本地文件系统一样使用共享资源

  使用完毕,可以使用umount命令解除挂载

  #umount /mnt/smb/win

阅读(3057) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~