~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

第一阶段讲解共享基质与网上邻居的特性

Samba文件服务器

它主要基于WINDOWS中的网上邻居所实现的.原理与概念与WIN都一样.

首先在讲之前,来复习下WIN下网上邻居中一些内容.下图所描述的.

在WIN中访问同一个工作组中可以使用网上邻居进行互访,它是使用主机名显示在同组中,当然像图所谈到的,也可以域名形式.成为域控成员或建立林与林之间信任关系来互访.不过它需要一种基质(主域控制器-AD).

在这里有个这样的问题,当我们访问工作组中的某台共享计算机中文件时,实际是个虚拟的目录,访问者并不知道该文件在被访问客户机所在的存储位置.

下面看到的是局域网上的主机之间认证关系(模型)

默认情况下,所有主机不需要身份验证,是以匿名形式访问的.通过上图可以通过两种方法对访问者进行验证,只有对被访问者认证后才能访问该主机上的资源----工作组模式和域服务器模式.等会会讲到在LINUX中来模拟用户需要身份验证来访问资源.

在WIN中通过共享权限与NTFS权限来设置共享目录的用户验证.也可以说成对系统进行加密,需要用户名和密码来进行授权才能访问共享目录.

下面看到是明白下,在访问之前,计算机需要具备一些组件协议与要求以访问方法.

从图中可以看到WIN有多种协议任意安装一种,但在LINUX中SAMBA服务器只能识别TCP/IP协议.安装WIN中需满足中的协议.

第一个协议是说明主机允许工作组中其他主机访问该台中的共享文件,第二协议是说明访问必需通过该协议进行传输.

对于LINUX中访问网上邻居

通过以下两种挂载方式来访问(两种路径).

#mount –t smbfs //server/sharname /localidr 或 #smbmount //server/sharename /localdir

其中mount –t smbfs 和 smbmount等同,-t smbfs 表示linux中samba访问文件类型,而//server表示所要访问的主机名或主机的IP地址,/sharename 将要访问那台主机上的共享目名称. /localdir 所表示的是把被访问那台主机上的共享目录文件上传或说挂载到本地主机上某个目录下进行存放.(只是临时)

也可以smbclient命令登陆到某台主机中资源.

#smbclient //server/sharename –U name%passwd

-U name%passwd 表示指定对方主机的用户名和密码,关于这个后面会详细讲到.关于网上邻居的内容就讲到这里..

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

第二阶段samba软件包介绍

Samba软件包是SAMBA项目组织成开发的,提拱了SMB/CIFS服务器与客户端程序.可以以到以上几个网点下载最新源代码和参考文档.

这里讲解是基本入门的安装RPM包安装. (三包)

Samba 服务器软件包

Samba 客户端工具

Samba 通用工具和库

在以前LINUX版本(LINUX9.0前)中,在安装这三个包之前需要解决安装过程中的依赖关系.因此需要安装rpmdb-fedora*.rpm包才能进行相应的包安装.如果是新版本的话(RHLE4或5)则不需要依赖关系就可,由于系统默认就已安装好.(其实在RHLE4之后的版本中关于SAMBA软件所有包都已默认安装好拉).

下面我们看一详细的操作过程 (以RHL9系统步骤安装),但笔者是以RHLE4作为系统来演试的,所以在下操作中会有一些软件包的版本不同(由于更新).

弹出光驱器:eject

收回光驱器:eject -t

首先挂载光盘:mount /media/cdrom

进入光盘目录: cd /media/cdrom/RedHat/RPMS/

安装依赖包: rpm -ivh rpmdb-redhat-4-0.20050107.i386.rpm

依赖包安装后,继续来安装SAMBA软件包.

图示,利用了rpm –ivh –aid samba*.rpm所表示的是安装SAMBA所有被依赖的软件包,这引些软件包是借助rpmdb这个包.也就是说rpmdb是安装这些的辅助包.可以看到,其实第一包cpu-libs与samba服务器无关也被安装了,说明此包也需要依赖rpmdb包安装.

下面检查系统是否完整安装所需要的软件包

利用rpm –qa | gerp samba命令查看

接下来看下所安装的配置文件列表(服务器工具)

Rpm –ql samba | more命令,只列出了一小部分.兴趣的朋友可以自己去看下.

[root@ server root]# rpm -ql samba | more

/etc/logrotate.d/samba

/etc/pam.d/samba

/etc/rc.d/init.d/smb smb服务器的启动脚本.

/etc/samba/smbusers

/etc/sysconfig/samba

/lib/security/pam_smbpass.so

/usr/bin/mksmbpasswd.sh

/usr/bin/smbcontrol

/usr/bin/tdbtool

/usr/lib/samba/vfs

/usr/lib/samba/vfs/audit.so

/usr/sbin/nmbd

/usr/sbin/smbd

/usr/share/doc/samba-3.0.10

/usr/share/doc/samba-3.0.10/COPYING

/etc 下的文件都是相应的配置文件

/usr/bin 基本是工具.二进制可执行文件.

/usr/lib 都是几个共享的库

/usr/sbin都是超级用户使用的程序,一般是服务的主程序,这里SMB有两个主程序

Nmbd:主要作用是提拱名称解析.身份验证和索引目录的查询.以及提拱共享名

Smdb:主要作用是提拱传输数据

/usr/share/doc是帮助文档(非常丰富)

关于这方面的帮助文档,SAM提拱了两份最权威的文档.像市场上关于SAMBA书籍的介绍基本来自这两文档中.它的存放位置.

# ls /usr/share/doc/samba-3.0.10/

Samba-Developers-Guide.pdf和Samba-HOWTO-Collection.pdf两个FDF格式的帮助资料.

关于客户端的工具利用rpm –qa samba-client | more 进行查看..还是一样其中列出了帮助文档.

下面介绍下samba一些客户端工具

我们需要借助局域有台WINDOWS(XP/2000/2003/)共享目录机器.作为访问对象.根据图中所级给予的工具进行操作.

由于LINUX不允许浏览形式访问其他主机共享目录,所以只能通过某些字符命令.

Smbtree---目录树方式

(1) Smbtree 相当浏览器的形式来访问的.

[root@ server root]# smbtree

Password:

WORKGROUP

\\win2000

这里不需要输入密码,表示以匿名身份登陆,向局域网所有主机发送广播,可以看到当前工作组中的计算机.

(2) 上面一种相当于以WIN服务器(浏览器)形式查询访问,在这里也可以使用广播形式查询.

[root@ server root]# smbtree -b

Password:

WORKGROUP

\\win2000

(3) 如果指定要查询工作组中的或域控中的.可以使用

[root@ server root]# smbtree -b -D

Password:

WORKGROUP

(由于当前环境中没有域控,所以只能查询到工作组)

(4) 如果访问某台主机时,且要访问那台主机需要身份验证的话.可以使用以下命令

[root@server root]# smbtree -b -U redhat%redhat

WORKGROUP

\\win2000

Nmblookup 工具

它通过广播形式发送形式解析出局域网中那台主机可以被访问.

我们也可以查看当前局域网哪些主机是活跃且可以被访问的.使用nmblookup \*(表示nmblookup广播局域所有主机,发送请求.)

可以看到同网段的主机回应(10.0.0.241/1),还有其他网段的主机(那是不能被访问的)

利用smbclient –L /hostname或/主机IP地址

在密码提示符下,直接回车.表示以匿名身份登陆,可以看到被访问的客户端并没有对匿名提拱任何共享目录.

利用身份形式登陆吧.来查询主机上的共享目录文件.

用户名和密码都为redhat.也可以写成

Smbclient工具

如何查看客户端查看共享的目录文件呢.有两种方式

第一种是前面所讲到的mount挂载方式 (mount //server或IP/sharename /local)

第二种是前面所讲到的smbclient方式(smbclient //server域IP/sharename –U name%passwd)

这里使用第二种方法

看到smb: \>形式表示登陆成功,类似WIN中的DOS界面,敲HELP可以杳看帮助命令.

(与FTP服务器中命令基于相同).

del删除远程主机文件。

help[cmd]显示smb内部命令cmd的帮助信息,如help get。

ls[remote-dir][local-file]显示远程目录remote-dir,并存入本地loca l-file。

Get remote-files从远程下主机下载共享文件到本地主机上.

mget remote-files传输多个远程文件。

mkdir dir-name 在远程主机中建一目录。

put local-file[remote-file]将本地文件local-file传送至远程主机。

Mput local-file[remote-file]将本地多个文件传送到远程主机

pwd显示远程主机的当前工作目录。

quit同bye,退出smb会话。

rmdir dir-name删除远程主机目录。

Dir显示远程主机共享目录的文件

Cd 切换当前目录位置.

可以通过以上的命令进行自己所要访问的文件内容下载到本机主机,也可将本地某些文件上传到远程主机上.

比如要将远程的主机的共享目录实现于本地主机目录操作一样,如何达成呢?利用挂载mount

利用smbmount //server或IP/sharename /localdir -o username=name%passwd

挂载后,切换到挂载到本地点的目录下.可以看到远程主机上被挂载的共享目录文件.只要权限允许可以随决对文件进行操作(相当于本机文件).---cp mv mkdir rm等一些操作.

最后一个工具sbmtar

主要对远程被访问主机上的共享目录文件进行备份(tar压缩格式)

利用smbtar命令进行过程备份工作,-s指定过程主机名称或IP地址, -u后跟随远程主机系统的共享目录所要访问的用户名,-p 用户名的密码. –x指定要对将要备份远程主机共享目录名称, -t 表示是备份后存放本地主机一个后缀为.tar格式的新文件.

在做这一步之前需要做如下的操作,否则的话备份远程文件将会失败.

进入smbtar配置文件中进行修改.

#vi /usr/bin/smbtar 看到最后几项内容

eval $SMBCLIENT "'\\\\$server\\$service'" "'$password'" -U "'$username'" \

-E -N $log -D "'$cdcmd'" ${clientargs} \

-T${tarcmd}${tarargs} $blocksize $newer $tapefile '${1+"$@"}' $verbose

其中我们看到-N,其中的含义是表明默认访问(smbtar)时,不论是使用户名或密码了,还是没使用都是以匿名身份登陆来访问的,前面讲到,以匿名身份形式登陆是看到不到远程主机上的任何共享目录文件的.因此要成功备份远程共享目录文件则需要把smbtar配置文件中的-D删除. 最终文件变为:

之后操作如下:

其中利用tar –tvf 查询压缩后(备份)的文件包.

下面学习下samba服务器配置.(基本配置,详细配置将在后面讲到)

基本可以分为三步

第一步:修改配置文件/etc/samba/smb.conf

Workgroup = workgroup(工作组)或Domain name(域名) ----所表示是将主机加入到工作组中或一个域环境(AD)

Security = share----表示安全级别(共享级)

[docs]-------指定共享名

comment = Mary's and Fred's stuff ------对当前共享目录注释信息

path = /usr/somewhere/shared------共享目录的路径

public = no/yes--------共享目录文件是否公开

下面看具体的操作过程:

#vi /etc/samba/smb.conf 进入配置文件

# workgroup = NT-Domain-Name or Workgroup-Name

workgroup = MYGROUP

工作组默认是mygroup修改为workgroup(由于局域中的工作组都为workgroup)

# Security mode. Most people will want user level security. See

# security_level.txt for details.

security = use

默认安全是用户级别(需要身份验证访问目录文件)将修改为share(共享级别)

利用shift+g跳到最后一行(创建共享目录文件夹)

第二步:重新启动smb服务器

#sevice smb restart

Shutting down SMB services: [FAILED]

Shutting down NMB services: [FAILED]

Starting SMB services: [ OK ]

Starting NMB services: [ OK ]

其实有两个服务器重新启动了(SMB和NMB)

设置服务器的启动状态(随计算机启动而同时启动)

[root@server root]# chkconfig smb --list

smb 0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@ server root]# chkconfig --level 345 smb on

[root@ server root]# chkconfig smb --list

smb 0:off 1:off 2:off 3:on 4:on 5:on 6:off

第三步:测试

[root@server root ]# smbclient -L localhsot –N (-N表示以匿名身份登陆,不需要密码的提示)

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.10-1.4E]

Sharename Type Comment

--------- ---- -------

share Disk this is test

IPC$ IPC IPC Service (Samba Server)

ADMIN$ IPC IPC Service (Samba Server)

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.10-1.4E]

Server Comment

--------- -------

LOCALHOST Samba Server

Workgroup Master

--------- -------

WORKGROUP

接下来在WIN中来访问LINXU下的共享目录文件.

两种方法.一.使用WIN上网上邻居查看主机名

二.使用UNC路径访问 //server或IP

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

第三阶段 Samba配置文件

这次主要来学习SAM详细的配置文件.讲到主要关键和用到的配置选项.

进入服务器的配置文件

# vi /etc/samba/smb.conf

在这里我列出整个配置的文件来参考及对关键字段加以说明:

# This is the main Samba configuration file. You should read the

# smb.conf(5) manual page in order to understand the options listed

# here. Samba has a huge number of configurable options (perhaps too

# many!) most of which are not shown in this example

#

# Any line which starts with a ; (semi-colon) or a # (hash)

# is a comment and is ignored. In this example we will use a #

# for commentry and a ; for parts of the config file that you

# may wish to enable

#

# NOTE: Whenever you modify this file you should run the command "testparm"

# to check that you have not made any basic syntactic errors.

#

#======================= Global Settings =====================================

[global]

# workgroup = NT-Domain-Name or Workgroup-Name

workgroup = workgroup

(表示计算机的属于工作组环境还是域环境.)

netbios name = 自定义名(通过hostname 查看系统当前默认NETBIOS名,通过nmblookup测试服务主机名.是可以找到的.在这里就可以修改系统所对应的NETBISO名了.)

# server string is the equivalent of the NT Description field

server string = Samba Serve

(表示当前计算机的类型或说服务器类型)

# This option is important for security. It allows you to restrict

# connections to machines which are on your local network. The

# following example restricts access to two C class networks and

# the "loopback" interface. For more examples of the syntax see

# the smb.conf man page

; hosts allow = 192.168.1. 192.168.2. 127.

(系统默认没有拒绝任何地址的主机)

# if you want to automatically load your printer list rather

# than setting them up individually then you'll need this

printcap name = /etc/printcap

load printers = yes

# It should not be necessary to spell out the print system type unless

# yours is non-standard. Currently supported print systems include:

# bsd, sysv, plp, lprng, aix, hpux, qnx

; printing = cups

# This option tells cups that the data has already been rasterized

cups options = raw

# Uncomment this if you want a guest account, you must add this to /etc/passwd

# otherwise the user "nobody" is used

; guest account = pcguest

# this tells Samba to use a separate log file for each machine

# that connects

log file = /var/log/samba/%m.log (日记默认路径,用户可以自定义日记文件名.介意安服务器分类对应来修改,方便以后管理,%m可把用户分为不同计算机类型访问的日记信息,关于%相关通过man samba查看

ls /var/log/samba可以看到.

[root@server root]# ls /var/log/samba

0.0.0.0.log 192.168.0.21.log nmbd.log www.log

192.168.0.17.log localhost.log smbd.log

# all log information in one file

# log file = /var/log/samba/smbd.log

# Put a capping on the size of the log files (in Kb).

max log size = 50

# Security mode. Most people will want user level security. See

# security_level.txt for details.

security = usre

(安全级别.系统默认为user,一般有三种常用级别user,share,server)

user是需要访问者身份验证访问共享目录文件

share正好与user相反,以匿名身份形式访问即可

server类似于user也需要身份验证功能,不过选择server作为系统的安全级别,那么需要匹配以下字段 ; password server = <server名>

# Use password server option only with security = server

; password server = <NT-Server-Name>

# Password Level allows matching of _n_ characters of the password for

# all combinations of upper and lower case.

; password level = 8

; username level = 8

# You may wish to use password encryption. Please read

# ENCRYPTION.txt, Win95.txt and WinNT.txt in the Samba documentation.

# Do not enable this option unless you have read those documents

; encrypt passwords = yes (用户访问当前计算机上的共享目录所使用的密码都是一致,否则samba服务器不识别,从而不通过,也可以同时不需要密码.如果是WIN客户机访问则需要改注册表,也使得WIN系统要以明文形式传输,但不介意这样做.)

; smb passwd file = /etc/samba/smbpasswd

(它是针对samba服务器独立samba用户密码存入路径,它是与系统用户不相同的用户和码)

# The following are needed to allow password changing from Windows to

# update the Linux system password also.

# NOTE: Use these with 'encrypt passwords' and 'smb passwd file' above.

# NOTE2: You do NOT need these to allow workstations to change only

# the encrypted SMB passwords. They allow the Unix password

# to be kept in sync with the SMB password.

; unix password sync = Yes

; passwd program = /usr/bin/passwd %u

; passwd chat = *New*UNIX*password* %n\n *ReType*new*UNIX*password* %n\n *passwd:*all*authentication*tokens*updated*successfully*

# Unix users can map to different SMB User names

; username map = /etc/samba/smbusers

# Using the following line enables you to customise your configuration

# on a per machine basis. The %m gets replaced with the netbios name

# of the machine that is connecting

; include = /etc/samba/smb.conf.%m(控制语句,可根据不同客户机需要来配置,由%所跟的参数来决定,如%m是指计算机名,%i 根据客户机的IP地址)

# Most people will find that this option gives better performance.

# See speed.txt and the manual pages for details

socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192

# Configure Samba to use multiple interfaces

# If you have multiple network interfaces then you must list them

# here. See the man page for details.

; interfaces = 192.168.12.2/24 192.168.13.2/24(表示那块网卡的IP来为当前SAM服务器提拱服务.共享服务,)

# Configure remote browse list synchronisation here

# request announcement to, or browse list sync from:

# a specific host or from / to a whole subnet (see below)

; remote browse sync = 192.168.3.25 192.168.5.255

# Cause this host to announce itself to local subnets here

; remote announce = 192.168.1.255 192.168.2.44

# Browser Control Options:

# set local master to no if you don't want Samba to become a master

# browser on your network. Otherwise the normal election rules apply

; local master = no

# OS Level determines the precedence of this server in master browser

# elections. The default value should be reasonable

; os level = 33

# Domain Master specifies Samba to be the Domain Master Browser. This

# allows Samba to collate browse lists between subnets. Don't use this

# if you already have a Windows NT domain controller doing this job

; domain master = yes

# Preferred Master causes Samba to force a local browser election on startup

# and gives it a slightly higher chance of winning the election

; preferred master = yes

# Enable this if you want Samba to be a domain logon server for

# Windows95 workstations.

; domain logons = yes

# if you enable domain logons then you may want a per-machine or

# per user logon script

# run a specific logon batch file per workstation (machine)

; logon script = %m.bat

# run a specific logon batch file per username

; logon script = %U.bat

# Where to store roving profiles (only for Win95 and WinNT)

# %L substitutes for this servers netbios name, %U is username

# You must uncomment the [Profiles] share below

; logon path = \\%L\Profiles\%U

# All NetBIOS names must be resolved to IP Addresses

# 'Name Resolve Order' allows the named resolution mechanism to be specified

# the default order is "host lmhosts wins bcast". "host" means use the unix

# system gethostbyname() function call that will use either /etc/hosts OR

# DNS or NIS depending on the settings of /etc/host.config, /etc/nsswitch.conf

# and the /etc/resolv.conf file. "host" therefore is system configuration

# dependant. This parameter is most often of use to prevent DNS lookups

# in order to resolve NetBIOS names to IP Addresses. Use with care!

# The example below excludes use of name resolution for machines that are NOT

# on the local network segment

# - OR - are not deliberately to be known via lmhosts or via WINS.

; name resolve order = wins lmhosts bcast

(这是客户机查询服务器的顺序,首先是查找局域网中wins服务器,这个wins服务器可以以自己冲当,如果局域网有wins服务器,则通过wins server = w.x.y.z(指定wins服务器IP地址).如果没有的话,则查询后的lmhost(路径/etc/samba/lmhosts)相当于windows中的host文件信息一样,也是ip地址对应主机名).如果还不能找到.则客户端向局域网发送广播).

# Windows Internet Name Serving Support Section:

# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server

; wins support = yes

(前面;去掉表示自己当wins服务器,为客记机netbios名解析工作)

# WINS Server - Tells the NMBD components of Samba to be a WINS Client

# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both

; wins server = w.x.y.z

(指定wins服务器的IP地址.这个选项不能与wins support = yes 同时使用).

# WINS Proxy - Tells Samba to answer name resolution queries on

# behalf of a non WINS capable client, for this to work there must be

# at least one WINS Server on the network. The default is NO.

; wins proxy = yes

# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names

# via DNS nslookups. The built-in default for versions 1.9.17 is yes,

# this has been changed in version 1.9.18 to no.

dns proxy = no

# Case Preservation can be handy - system default is _no_

# NOTE: These can be set on a per share basis

; preserve case = no

; short preserve case = no

# Default case is normally upper case for all DOS files

; default case = lower

# Be very careful with case sensitivity - it can break things!

; case sensitive = no

#============================ Share Definitions ==============================

idmap uid = 16777216-33554431

idmap gid = 16777216-33554431

template shell = /bin/false

winbind use default domain = no

[homes]

comment = Home Directories

browseable = no

writable = yes

# Un-comment the following and create the netlogon directory for Domain Logons

; [netlogon]

; comment = Network Logon Service

; path = /home/netlogon

; guest ok = yes

; writable = no

; share modes = no

# Un-comment the following to provide a specific roving profile share

# the default is to use the user's home directory

;[Profiles]

; path = /home/profiles

; browseable = no

; guest ok = yes

# NOTE: If you have a BSD-style print system there is no need to

# specifically define each individual printer

[printers]

comment = All Printers

path = /var/spool/samba

browseable = no

# Set public = yes to allow user 'guest account' to print

guest ok = no

writable = no

printable = yes

# This one is useful for people to share files

;[tmp]

; comment = Temporary file space

; path = /tmp

; read only = no

; public = yes

# A publicly accessible directory, but read only, except for people in

# the "staff" group

;[public]

; comment = Public Stuff

; path = /home/samba

; public = yes

; read only = yes

; write list = @staff

# Other examples.

#

# A private printer, usable only by fred. Spool data will be placed in fred's

# home directory. Note that fred must have write access to the spool directory,

# wherever it is.

;[fredsprn]

; comment = Fred's Printer

; valid users = fred

; path = /homes/fred

; printer = freds_printer

; public = no

; writable = no

; printable = yes

# A private directory, usable only by fred. Note that fred requires write

# access to the directory.

;[fredsdir]

; comment = Fred's Service

; path = /usr/somewhere/private

; valid users = fred

; public = no

; writable = yes

; printable = no

# a service which has a different directory for each machine that connects

# this allows you to tailor configurations to incoming machines. You could

# also use the %u option to tailor it by user name.

# The %m gets replaced with the machine name that is connecting.

;[pchome]

; comment = PC Directories

; path = /usr/pc/%m

; public = no

; writable = yes

# A publicly accessible directory, read/write to all users. Note that all files

# created in the directory by users will be owned by the default user, so

# any user with access can delete any other user's files. Obviously this

# directory must be writable by the default user. Another user could of course

# be specified, in which case all files would be owned by that user instead.

;[public]

; path = /usr/somewhere/else/public

; public = yes

; only guest = yes

; writable = yes

; printable = no

# The following two entries demonstrate how to share a directory so that two

# users can place files there that will be owned by the specific users. In this

# setup, the directory should be writable by both users and should have the

# sticky bit set on it to prevent abuse. Obviously this could be extended to

# as many users as required.

;[myshare]

; comment = Mary's and Fred's stuff

; path = /usr/somewhere/shared

; valid users = mary fred

; public = no

; writable = yes

; printable = no

; create mask = 0765

[share]

comment = this is test

path = /etc/share/

public = yes

directory mask = 0777

[doc]

comment = welcome to

path = /usr/share/doc

public = yes

directory mask = 0777

可以看到全部的配置文件信息,关于文件中几种颜色字段表示的含义是

紫色那段---可以看到前面被#注释(没有意义).它主要的作用是提示用户在它下面的文件[global]中信息的主要工作是干什么的.

红色那段----基本都是配置的主要文件.(对SMA服务器严格的配置)

绿色那段----它是系统默认HOME目录中的共享.除了用户自定义的共享目录以外.文件中[]都为系统[HOME]中的共享信息.

青色那段---它是用户自定义的共享目录文件信息.

提:关于文件的中# 和; 这两个符号的表示都是注释.但#不能去掉,而;可以删除.如果把某字段前的#去掉了.那么这字段表示错误有语法了.而字段前有;被去掉表示这字段被激活,有意义了,来解释这段语句的信息.

在配置文件也可以重新启动SAMBA服务器,在未行模式下:!service samba restart

在这里详细提出安全级别的

前面我们提到过这三种安全级别基本概念.这里从图中可以看出来各自的作用.关于第三者server的安全级别,所有要验证的用户都在存放一台服务器的,从则本地不需要这个用户.其他客户端就可以访问该主机上的共享目录.再次就是user它是需要用户身份的.但是它是针对windows主机,而对于linux客户端是无效的.

接下来学习下访问控制的设置

主要作用是对于samba更加严格的进行配置.允许被创建的samba用户哪些被允许访问共享目录文件夹,哪些用户被拒绝访问.还可以针对局域网中某台主机设置访问的规则和网段的范围设置策略.

从图中可以看到有两种访问控制(全局和局部).全局是对整个共享目录文件生效的.而局部是对某些共享文件夹作出控制.

其中注意的地方是.如果在对某共享目录文件夹设置时,deny 在allow发生冲突的话,请记住一句话”允许优先”.这时包括全局与局部之间的关系.以及局部内部之间的关系.

可以操作几个关键要点

比如按照前面的所配置的共享目录文件.

安全级别我这里保持security = share(匿名身份验证)

#vi /etc/samba/smb.conf

重启SAMBA服务器后,通过WIN客户端进行访问是可以的.从而证明了允许优先的结论.

如果有这里我们拒绝某台客户端的访阅应该如何设置呢?

在这里我们通过一条规则EXCEPT也就是被去除的IP 主机地址.

这样就可拒绝10.0.0.241一台主机的访问.而允许10.0.0.网段其他主机的访问.

如果这是这样做的话将是什么结果呢?

利用客户机访问结果是被拒绝的.由于只有允许,而允许范围里没有地址.所以最终是被拒绝的.还有一点就是allow与dney 同时使用.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

第四阶段 samba用户账号

在系统默认情况下.共享目录是共用的,意思就是说所有用户都可以访问(public = yes).为了后面的实验我在这里修改public = no,任何用户不能访问

对于指定某用户来访问的标准(samba库中的用户账号)

它是利用valid users = <username><@groupname>. 可对用户或用户工作组进行设置.

如笔者在这里对某用户进行配置,只允许该用户能访问服务器上的共享目录文件夹.

进入vi /etc/samba/smb.conf最后一行新建一项目录

可以看到public为no,表示不允许匿名用户访问的,因此后面添加了一位有效访问用户

Valid users = redhat(只允许redhat访问)

samba用户是必需是当前系统所存在的系统用户,然后则要把该用户加入到sambusers目录中,.否则samba服务器是不允许用户访问共享目录文件夹的

当前系统有个redhat全法用户存在,则现在我们让它成为samba服务器用户.

#smbpasswd –a redhat 随后提示输入密码(为用户在smb中所需要的密码).

加入这后,用户会写进smbpasswd中,通过more /etc/samba/smbpasswd查看.

关于sambpasswd的用法.可以查看帮助文档 smbpasswd –help

options:

-L local mode (must be first option)

-h print this usage message

-s use stdin for password prompt

-c smb.conf file Use the given path to the smb.conf file

-D LEVEL debug level

-r MACHINE remote machine

-U USER remote username

extra options when run by root or in local mode:

-a add user 添加用户

-d disable user 取消(禁止)用户访问的权限.

-e enable user 开启用户访问的权限

-i interdomain trust account

-m machine trust account

-n set no password 清空用户密码

-w PASSWORD ldap admin password

-x delete user 删除用户

注意一点.用户已经创建完成,使用windows客户端可以访问,则需要身份验证来进行访问才行.(前提是smb.conf全局配置文件中的安全级别为secuity = users)

前面我们提到过,smaba用户必需是系统已存在的合法用户.从而就存在这样一个问题.(安全隐患),当访问者访问samba服务器的时候,就可猜测当前服务器中有这样一个用户的存在.因此我们为了防治访问者能猜测出服务器上有这样的用户账户.所以这里利用一种技术叫用户账户映射来防治这类问题的发生.

实际它的原理就是利用系统用户映射一个访问samba服务器虚拟用户.利用解决访问难易猜测出所使用的访问用户是否为当前系统上用户.防治有意***者对服务器造成恶意损害.

在操作之前.服务默认是不允许使用映射功能的.

修改smb.conf配置中的语句.将前面;号去掉.

主体方法有两种

第一种方法:#sambuseradd redhat: tom jack (当前系统用户对应两个虚拟用户tom 和jack).

第二种方法:创建映射用户对应列表

# vi /etc/samba/sambusrs

重启服务器,使用windows客户端访问.这是提示身份验证可以输入tom或jack其中任一用户.密码为redhat用户添加smapasswd时所建密码.

Linxu客户端的访问多种方法

第一种方法

#smbmount //server/sharname –o username=name%passwd

第二种方法

#smbclient –L server或IP地址 –U name%passwd

以上两种方法也可以使用samba服务器访问windows客户机上的共享目录文件夹.

接下来学习下samba用户的权限设置

假如现在有这样一个案例.两个用户都允许访问共享目录文件.但拒绝其中一个用户的写入权限.应如何操作?

这个图表示共享目录允许redhat 和itlab两个用户访问,但是只允许redhat访问目录后有写入的权限.而itlab则无权写入

注意这样的一个问题.所说在共享目录中设置了redhat的写入权限.但是用户的最终权限取决与用户本身拥有该目录的权限.下图看到.默认情况下是root用户所占有.通过chown 命令进行修改.将文件的属用户为redhat.

所以说最终权限为两者的结合,不过也是最严格的(交集)

我们也可以对用户组进行设置.这里还是以redhat用户作例子.首先查看该用户属组

.

查看结果是属于redhat组中.下去则可修改配置文件smb.conf为.下图所示

同理.与前面用户设置一样.则我们也要修改目录路径中文件的权限.通过chgrp 命令可对文件属组进行修改.

在这里还有设置.cereate mask和directory mask 两种配置,它们的主要作用保证了目录文件的安全和严格性.使得系统得到安全的保护.

主要共享目录文件的配置如下

Create mask指定设置文件权限(660)

Directory mask指定设置目录权限(770)

设置之后.访问者访问目录或者文件时主有严格性要求权限.

从中我们实现某用户和组中的用户只能说自己目录下的文件..实现更严格的配置操作

最后总结下用户的配置权限可以设置几项内容有如下

comment = Mary's and Fred's stuff ------对当前共享目录注释信息

path = /usr/somewhere/shared------共享目录的路径

valid users = mary fred--------指定合法用户对共享目录文件进行访问(也可以不指定)

public = no/yes--------表示所有用户都可以访问共享目录(匿名).一种控制语句

writable = yes/no--------用户访问共享文件后是否有写入的权限

readonly =yes /no-------是否用户访问共享文件后仅为读的权限

only guest = yes/no---------是否仅有来宾用户访问共享目录文件

printable = no/yes---------系统默认的打印设备是否共享

create mask = 0765--------创建文件默认权限

directory mask = 0777----------创建目录权限

在linux客户端中可以将服务器上属于自己的目录文件永远性的挂载在自己的主机上.也就是映射到本地主机目录上.(相当于windows中的映射驱动器).则需要automouter工具(系统默认已安装了autofs软件包).

#vi /etc/auto.misc在配置文件中最后添加一段语句

这是地LINUX客户机设置的.//10.0.0254/share表示该客户机在服务器10.0.0.254中能让访问share共享目录.从而使用auto.misc设置进行永久的挂载到本机上.还可以实现与计算机同时启动而挂载的效果

在这里介绍一个samba的测试工具.主要作用是检查smb.conf中是否有语法错误的现象.如有下图所提示的信息.表示配置文件中没有语法的错误.(loaded services file ok).若有错误的信息,屏幕会有错误信息的提示出来.从而加以修改.

Testparm工具还有一个功能就是检测某个客户能否可以访问服务器以及访问服务器上哪些资源的目的.可以使用下图所写入的命令

Testparm /etc/samba/smb.conf 后面跟客户机的名称 以及IP地址

我们可以看到.其中Allow都是客户机能否访问服务器上的哪些资源信息了.

转载于:https://blog.51cto.com/vdata/301327

Linux-SAMBA服务器的配置相关推荐

  1. linux samba服务器的配置

      说明:下面是我copy过来的,但是,我只用了几个命令就搞定了.两个命令:第一个建用户:第二个启动服务.然后就OK了.但下面的贴出来供大家参考. 建用户:smbpassword -a user 首先 ...

  2. samba 服务器的配置基础

    简单介绍samba服务器的配置基础. samba的核心是两个守护进程smbd和nmbd程序,在服务器启动到停止期间持续运行.Smbd和nmbd使用的全 部配置信息全都保存在smb.conf文件中.Sm ...

  3. Samba服务器的配置

    Samba服务器的配置 实验步骤: 1.安装有关Samba的RPM包(samba.samba-common.samba-client) 2.创建Samba用户 3.修改配置文件 4.重启samba服务 ...

  4. Samba服务器的配置与使用

    一.简介 Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件,SMB(Server Message Block)服务器消息块 Samba最大的功能是可以用于Linux与wind ...

  5. ubuntu系统samba服务器安装,Ubuntu 20.04.1安装Samba服务器及配置

    Ubuntu 20.04.1安装Samba服务器及配置 1查看Ubuntu的版本 agold@ubuntu:~$ cat /etc/issue 2更新软件 agold@ubuntu:~$ sudo a ...

  6. windows/linux查看服务器CPU配置命令

    基本概念: Intel的处理器分为至强Xeon.酷睿Core.赛扬Celeron.奔腾Pentium和凌动Atom5个系列. 英特尔® 酷睿™ .奔腾® .赛扬® 系列处理器都是面向笔记本或台式机的C ...

  7. linux安装Samba服务器及配置(windows及ios均可连接互传文件),帮你解决多设备共享文件的问题

    1.前言 在嵌入式系统开发应用平台中,tftp.nfs和samba服务器是最常用的文件传输工具,tftp和nfs是在嵌入式Linux开发环境中经常使用的传输工具,samba则是Linux和Window ...

  8. 191_Ubuntu 18.04安装Samba服务器及配置

    局域网下使用samba服务在Linux系统与Windows系统直接共享文件是一项很方便的操作.以Ubuntu为例配置samba服务,Linux服务器的版本是Ubuntu 18.04.1 LTS. 在终 ...

  9. linux搭建服务器的配置

    1.安装好linux系统之后,如果无法连接网络,先设置代理,配置apt的流量走代理: #命令 vim /etc/apt/apt.conf #配置文件内容 Acquire::http::Proxy &q ...

  10. Samba服务器的配置和使用

    一.安装samba sudo apt-get update sudo apt-get install samba samba-common-bin sudo apt-get install libta ...

最新文章

  1. Hyperledger Fabric 核心模块(6)Fabric-ca-server
  2. 4.事务提交过程,事务基本概念,Oracle中的事务生命周期,保存点savepoint,数据库的隔离级别
  3. node.js中的框架
  4. metasploit终端命令大全 MSF
  5. android注册界面高级,Android用户注册界面简单设计
  6. pandas 保存数据到excel,csv
  7. spark机器学习 源码解析及原理分析
  8. OSI网络七层协议与TCPIP协议
  9. 第一篇 外贸企业出口退税
  10. 【POJ 2719 --- Faulty Odometer】
  11. Python+OpenCV教程3:打开摄像头
  12. hive-对用户浏览网站的点击量按年月进行统计
  13. app启动页html模板,APP引导页设计的五种常见表现方式
  14. BS与CS的联系与区别
  15. 使用Verilog来实现奇数分频
  16. 3D旋转相册+背景音乐,纯js版本
  17. 椭圆曲线图像加密 matlab,椭圆曲线ECC加密算法入门介绍(三、四)
  18. Docker启动MySql容器Exited (1) 7 seconds ago问题解决
  19. 网络安全与网站安全及计算机安全:如何使用Kali Linux的MSF进行MS12-020安全演练
  20. 计算机毕业设计开题报告遇到问题及解决办法(建议收藏)

热门文章

  1. android universal image loader 缓冲原理详解
  2. 改变,从跨出第一步開始——记海大ITAEM团队首次IT讲座掠影
  3. POJ 1170 Shoping Offers(IOI 95)
  4. 各种Java日志框架的比较
  5. 读《程序员到底怎么了?-》
  6. 北京点击科技有限公司董事长兼总裁——王志东经典语录4
  7. Android recipe 在代码中写布局
  8. RamDisk加速Windows 7?
  9. grails 转为java_创建一个grails项目,然后转成maven项目
  10. vmware 8 精简 安装版_被困免安装版下载