samba

安装配置samba:

准备工作:

173/udp(NetBIOS)

138/udp

139/tcp

445/tcp

这些端口已经启动。

然后确定selinux已经关闭(#getenforce)。

一般我们装好系统之后samba都会安装的:yum list all samba*

这里我选用的是samba3x.i386  3.5.10-0.107.el5 版本

而一般系统默认为 samba.i386     3.0.33-3.37.el5  版本(卸载:rpm -e samba-client samba-common)

然后安装  samba3x.i386  3.5.10-0.107.el5 版本(yum -y install samba3x samba3x-client samba3x-common)

这种方法只局限于笔者所采用的环境,嘿嘿,其实这些简单安装你懂得。。。

当samba安装好之后它会启动两个进程:nmbd(提供NetBIOS)和smbd(提供文件共享)

samba的服务脚本:/etc/rc.d/init.d/smb

samba的配置文件:/etc/samba/所有文件,主配置文件是:smb.conf

打开主配置文件:vim smb.conf

解析:所有#开头的都是注释

      所有;开头的也是注释但是这个注释为可以启用的参数或指令或选项

 #======================= Global Settings ==================全局配置(定义),对所有共享都有效。

 #======================= Share Definitions ================家目录设置,共享定义。

 其中:

 [printers]                                                   共享名称

        comment = All Printers

        path = /var/spool/samba                                      共享路径

        browseable = no

        guest ok = no

        writable = no

        printable = yes

 # ----------------------- Netwrok Related Options -------------------------

#

# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH

#

# server string is the equivalent of the NT Description field

#

# netbios name can be used to specify a server name not tied to the hostname

#

# Interfaces lets you configure Samba to use multiple interfaces

# If you have multiple network interfaces then you can list the ones

# you want to listen on (never omit localhost)

#

# Hosts Allow/Hosts Deny lets you restrict who can connect, and you can

# specifiy it as a per share option as well

#

        workgroup = MYGROUP                             工作组

        server string = Samba Server Version %v          描述信息 %V为宏(类似常量一次定义永久有效)


;       netbios name = MYSERVER                         当前这台主机的netbios名称,没有启用就默认为当前主机的主机名的第一段


;       interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24 

;       hosts allow = 127. 192.168.12. 192.168.13.

 # --------------------------- Logging Options --------------------------关于日志的选项

#

# Log File let you specify where to put logs and how to split them up.

#

# Max Log Size let you specify the max size log files should reach


        # logs split per machine                     每个客户端来访问时使用独立的日志文件

        log file = /var/log/samba/log.%m             客户端主机自己的IP地址或名字

        # max 50KB per log file, then rotate

        max log size = 50                            日志文件最大为50KB


 # ----------------------- Standalone Server Options ----------------------独立守护进程

#

# Scurity can be set to user, share(deprecated) or server(deprecated)

#

# Backend to store user information in. New installations should 

# use either tdbsam or ldapsam. smbpasswd is available for backwards 

# compatibility. tdbsam requires no further configuration.


        security = user                      一种级别

        passdb backend = tdbsam              用户的账号和密码所存放的格式


 # ----------------------- 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

#

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

# elections. The default value should be reasonable

#

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

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

;       local master = no

;       os level = 33

;       preferred master = yes


 #============================ Share Definitions ==========================共享定义


[homes]                             它是定义一个用户是否可以通过samba访问自己的家目录的,对于不同的用户来讲它显示不同结果的

        comment = Home Directories          注释,说明信息

        browseable = no                     是否被其他用户看到浏览到

        writable = yes                      是否具有写权限

;       valid users = %S

;       valid users = MYDOMAIN\%S


[printers]                                   打印机

        comment = All Printers               所有打印机

        path = /var/spool/samba              路径

        browseable = no                      是否被其他用户看到浏览到

        guest ok = no                        是否允许来宾账号访问

        writable = no                        是否具有写权限

        printable = yes                      是否允许打印


此外常用的还有:

public = 表示是否具有读权限

read only = 表示是否是只读的 决不允许与writable = yes 同时存在

write list = 定义可写用户列表 

             @group  表示定义可写用户组名或+group

valid users = 只允许哪些用户访问(白名单)

invalid users = 不允许哪些用户访问(黑名单)

[shared_name]   共享名称

windows访问linux共享:

下面来定义一个共享

首先:mkdir -pv /share/test

然后: vim smb.conf 在最后添加:

再然后 命令#testparm 测试是不是有语法问题,再按回车键可以查看所有定义的有效信息

启动服务完成。

创建一个用户账号(采用的是hive)然后利用命令#smbpasswd -a hive 添加用户到smb用户中(密码设置尽量不要与系统密码一致)

使用windows打开查看:


在家目录中创建一个新文本

在进入系统查看结果:

由此可见家目录写入权限是可以的

而在tools中无法执行写入权限:

原因:

 

其他用户无权限,使用命令:#setfacl -m u:hive:rwx /share/test/更改权限 

 

这样就可以了。

linux访问windows共享:

1,熟悉一个命令:

smbclient

    -L NetBIOS_Name 或者直接输入IP地址       表示我们要访问哪台主机

-U username        实现认证的

-P 密码

2,在windows上创建一个共享文件

3,利用smbclient -L IP地址  进行连接 利用的是来宾账户进行连接的

4,若要利用用户名进行连接

首先,在windows上创建一个用户设置好密码

然后,smbclient -L IP地址 -U 用户名


5,利用smbclient //172.16.11.1/tools -U hive 可以查看内容上传内容下载内容(下载前要查看自己本地所在目录:!pwd ,切换本地目录用!cd)退出用exit

 

 

基于IP的访问控制

1,利用iptables

2,利用samba

   在配置文件中有一个hosts allow = IP地址      这是一个白名单,若要有多个IP地址使用空格隔开

3,使用samba-swat

    (1)安装与版本匹配的samba-swat

(2)启动xinetd(service xinetd start)

(3)启动swat(chkconfig swat on)

(4)重启xinetd

4,非独立进程都有一个单独的配置文件(/etc/xinetd.d/下)对应的都是进程的名称


5,打开/etc/xinetd.d/swat文件

 only_from       = 172.16.0.0/16            改为当前网段

6,用浏览器打开IP地址就可以了(记得要加上端口号:901)

 

关于samba安装配置使用已基本结束,若感觉不太习惯可使用ftp等。。。

 

 

你可能感兴趣的:(samba)