Samba简单介绍
Samba是在Linux和UNIX系统上实现与微软Windows操作系统的SMB/CIFS(Server Message Block/Common Internet File System)网络协定做连结的自由软件,由服务器及客户端程序构成。
目前的版本(v3)不仅可存取及分享SMB的资料夹及打印机,本身还可以整合入Windows Server的网域,扮演为网域控制站(Domain Controller)以及加入Active Directory成员。简而言之,此软件在Windows与UNIX系列OS之间搭起一座桥梁,让两者的资源可互通有无。
Samba 功能和应用范围
Samba 应该范围主要是Windows和Linux 系统共存的网络中使用;如果一个网络环境都是Linux或Unix类的系统,没有必要用Samba,应该用NFS更好一点;那Samba 能为我们提供点什么服务呢?主要是共享文件和共享打印机。
搭建samba共享服务器
一、首先检查一下服务器用的系统版本以及系统类型
1.[root@samba ~]# uname -a //查看内核版本详细信息,包括主机名称 Linux samba 2.6.18-308.el5 #1 SMP Tue Feb 21 20:06:06 EST 2012 x86_64 x86_64 x86_64 GNU/Linux 2.[root@samba ~]# lsb_release -a //查看系统的发行版本及厂商 LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch Distributor ID: CentOS Description: CentOS release 5.8 (Final) Release: 5.8 Codename: Final
二、首先安装与samba相关的三个数据包,如果用rpm安装不上,有依赖关系的话,那就直接用yum安装即可。
1.检查一下与samba相关的三个数据包是否已经安装成功
[root@samba ~]# yum install -y samba* [root@samba ~]# rpm -qa | grep samba samba-common-3.0.33-3.39.el5_8 samba-swat-3.0.33-3.39.el5_8 samba-3.0.33-3.39.el5_8 //samba:这个套件主要包含了 SAMBA 的主要 daemon档案 ( smbd 及 nmbd )、 SAMBA 的文件档 ( document )、以及其它与 SAMBA 相关的logrotate 设定文件及开机预设选项档案等。 samba-client-3.0.33-3.39.el5_8 //这个套件则提供了当 Linux 做为SAMBA Client 端时,所需要的工具指令,例如挂载 SAMBA 档案格式的执行档 smbmount等。
samba服务器主要提供以下两个服务程序。
smbd:为客户机提供服务器中共享资源(目录和文件等)的访问。
nmbd:提供基于NetBIOSS主机名称的解析,为windows网络中的主机进行名称解析。
2.smb.conf的配置文件默认放在/etc/samba目录下
[root@samba samba]# ll /etc/samba/ total 32 -rw-r--r-- 1 root root 20 May 18 2012 lmhosts -rw-r--r-- 1 root root 9733 May 118 2012 smb.conf -rw-r--r-- 1 root root 97 May 118 2012 smbusers
lmhosts:这个档案的主要目的在对应NetBIOS name 与该主机名称的 IP ,事实上,他有点像是/etc/hosts 的功能.
smbusers:创建smb的虚拟用户,存放在smbusers此文件中,用于验证登陆。
smb.conf:samba配置文件默认存放的目录,要是源码包安装可以自定义。
三、看一下配置文件中都有哪些信息,并且修改smb.conf配置文件
[root@samba samba]# grep -v "^[#;]" smb.conf | grep -v "^$" [global] workgroup = MYGROUP server string = Samba Server Version %v # logs split per machine # max 50KB per log file, then rotate security = user passdb backend = tdbsam # the login script name depends on the machine name # the login script name depends on the unix user used # disables profiles support by specifing an empty path load printers = yes cups optiOns= raw #obtain list of printers automatically on SystemV [homes] comment = Home Directories browseable = no writable = yes [printers] comment = All Printers path = /var/spool/samba browseable = no guest ok = no writable = no printable = yes
1.把配置文件重定向到一个文件,并且备份smb.conf的源文件
[root@samba samba]# grep -v "^[#;]" smb.conf | grep -v "^$" >>tt1.txt [root@samba samba]# mv smb.conf smb.conf.ori [root@samba samba]# mv tt1.txt smb.conf
2.下面详细介绍一下smb.conf配置文件中的重要信息
[root@samba ~]# vim /etc/samba/smb.conf [global] workgroup = MYGROUP //服务器所在的工作组名称,例如“WORKGROUP” server string = Samba Server Version %v//描述服务器的说明文字 hosts allow = 127. 192.168.1. 192.168.13. //默认是注释的,表示允许所有的IP地址访问, log file= /var/log/samba/%m.log //Samba服务器的日志文件,默认放在"/var/log/samba"这个目录下 security = share //一共有四个安全级别:share(共享)、user(需要本地服务器验证用户以及密码) 、server(有另一台服务器验证有户名和密码)、domain(由windows域控制器验证有户名和密码) passdb backend = tdbsam //tdbsam:使用数据库文件创建用户数据库。数据库文件叫passdb.tdb,在/etc/samba中。passdb.tdb用户数据库可使用smbpasswd ?a创建Samba用户,要创建的Samba用户必须先是系统用户。 load printers = yes//当Samba 服务启动时,自动加载的打印机配置文件 cups optiOns= raw //指定打印机使用的方式。 printcapname = /etc/printcap//默认设置打印机配置文件的位置目录 printcapname = lpstat printing = cups //设置打印系统类型,一般默认。只有在打印系统不是标准系统时才指定。 设置打印系统类型,一般默认。只有在打印系统不是标准系统时才指定。 #obtain list of printers automatically on SystemV [homes] //用户目录共享设置 comment = Home Directories //描述信息 browseable = no //设置其他用户是否可以浏览此共享文件。 writable = yes//设置此用户是否可写 [printers] //打印机共享设置 comment = All Printers //描述信息 path = /var/spool/samba//共享服务器默认路径 browseable = no //是否有目录浏览权限 guest ok = no //是否允许允许来宾访问 writable = no //用户对共享目录可写 printable = yes//是否可以打印,默认是yes(允许) [beyond] //自定义共享目录文件 comment = Public share with beyond file//描述信息 path = /var/public/beyond//自定义的共享文件目录路径 public = yes//共享目录允许所有用户访问及上传文件) readOnly= yes//权限为只读权限
3.查看下修改后的samba服务器的主配置文件smb.conf信息
[root@samba samba]# cat smb.conf [global] workgroup = MYGROUP server string = Samba Server Version %v log file= /var/log/samba/%m.log hosts allow = 127. 192.168.1. 192.168.13. # logs split per machine # max 50KB per log file, then rotate security = share passdb backend = tdbsam # the login script name depends on the machine name # the login script name depends on the unix user used # disables profiles support by specifing an empty path load printers = yes cups optiOns= raw #obtain list of printers automatically on SystemV [homes] comment = Home Directories browseable = no writable = yes [printers] comment = All Printers path = /var/spool/samba browseable = no guest ok = no writable = no printable = yes [beyond] comment = Public share with beyond file path = /var/public/beyond public = yes readOnly= yes
4.创建上边自定义指定的共享文件
[root@samba samba]# mkdir -p /var/public/beyond
[root@samba samba]# mkdir -p /var/public/beyonds/test
5.最后,需要开启smb服务才能生效
[root@samba samba]# /etc/init.d/smb start
四、在windows server 2003客户端上进行测试,访问linux上的samba服务器
3.可以进去,看到了原来创建的文件夹和文件,无法创建文件。为什么创建不了呢?是因为share的用户,设置read only = yes(只读权限)。
四.建立带验证性的文件共享服务器
1.创建三个smb账号和密码
[root@samba ~]# useradd tt1 [root@samba ~]# useradd tt2 [root@samba ~]# smbpasswd -a tt1 New SMB password: Retype new SMB password: Added user tt1. [root@samba ~]# smbpasswd -a tt2 New SMB password: Retype new SMB password: Added user tt2. [root@samba ~]# smbpasswd -a root New SMB password: Retype new SMB password: Added user root.
2.查看下修改的smb.conf的配置文件
[root@samba samba]# head smb.conf [global] workgroup = WORKGROUP server string = Samba Server Version %v log file= /var/log/samba/%m.log hosts allow = 127. 192.168.1. 192.168.13. # logs split per machine # max 50KB per log file, then rotate security = user passdb backend = tdbsam # the login script name depends on the machine name [root@samba samba]# tail smb.conf readOnly= yes [taokey] comment = Public share with taokey files path = /var/public/taokey public = no writable = yes valid users= tt1,tt2 @root writelist = root,tt2 directory mask = 0744 create mask = 0600
3.创建制定共享的目录和文件
[root@samba samba]# mkdir -p /var/public/taokey [root@samba samba]# mkdir -p /var/public/taokey/test [root@samba samba]# touch /var/public/taokey/taoyake.txt
4.重启smb服务器生效
[root@samba samba]# /etc/init.d/smb restart
5.重新用windows server 2003客户端访问samba服务器,弹出一个验证账号和密码的框
[root@samba samba]# tail smb.conf readOnly= yes [taokey] comment = Public share with taokey files path = /var/public/taokey public = no writable = yes valid users= tt1,tt2 @root writelist = root,tt2 directory mask = 0744 create mask = 0600
因为可写的只有tt2和root账号,所以tt1写不了
服务器的自带的文件权限对文件也要有写的权限,才可以写
[root@samba public]# chmod a+w /var/public/taokey
按上边的配置来说,应该是可以tt2是可以创建和删除文件的。咱们试试tt2,能不能创建或者删除文件。
注意:在测试samba时,默认情况下,第一次登陆后,再次登陆(\\samba服务器IP地址)会记住早先登陆的用户、密码。所以,如果想换个用户测试登陆的效果,可以先执行命令“net use * /del”,再次\\samba服务器IP地址,就会提示输入用户名、密码。