Samba是在Linux及Unix上实现SMB(Server Message Block)协议的一个免费软件,由服务器及客户端程序构成
samba的安全级别:
share: 不用验证
user :需要身份验证,需要samba账号库
server :需要其他服务器进行身份验证
domain :域 DC进行验证
Samba的服务器程序可以实现以下主要功能:1.文件及打印共享;2.计算机名与IP的解悉;3.WINS服务的支持;4.用户权限设置(如果配合Linux 的Quota还可以实现用户磁盘空间配额)。
安装和配置实例
1.挂载并切换到/mnt/cdrom/Server
安装samba 服务器器端
[root@localhost Server]# rpm -ivh perl-Convert-ASN1-0.20-1.1.noarch.rpm
[root@localhost Server]# rpm -ivh samba-3.0.33-3.14.el5.i386.rpm
1.修改配置文件如下:
[root@localhost samba]# pwd
[root@localhost samba]# vim smb.conf
/etc/samba
74 workgroup = MYGROUP #组名
75 server string = Samba Server Version %v #显示samba服务器的版本
76
77 ; netbios name = MYSERVER
78
79 ; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
80 ; hosts allow = 127. 192.168.12. 192.168.13.
81
82interfaces =192.168.10.10/24
查看端口如下:
3.网上邻居右键搜索计算机 输入192.168.10.10搜索如下:
1.添加一个ip
[root@localhost ~]# ifconfig eth0:0 192.168.10.20
再次使用搜索192.168.10.20 可以看到也可以访问到samba服务
下面就做 绑定ip,和控制来源访问的设置。
编辑配置文件如下:
82 interfaces =192.168.10.10/24 #设置要绑定的ip
83 bind interfaces only=YES #开启绑定功能
84 hosts allow = 127. 192.168.20.
#来源控制访问允许 自己,20网段的ip进行访问,也可以是单个ip
92 log file = /var/log/samba/%m.log #日志位置
93 # max 50KB per log file, then rotate
94 max log size = 50 #日志最大限制
当有客户端访问时,将为该客户端产生一个ip日志和主机名日志
[root@localhost samba]# pwd
/var/log/samba
如下:
[root@localhost samba]# ll
-rw-r--r-- 1 root root 0 12-20 06:56 192.168.10.1.log
-rw-r--r-- 1 root root 0 12-20 06:57 192.168.10.30.log
drwx------ 4 root root 4096 12-19 13:48 cores
-rw-r--r-- 1 root root 13007 12-20 07:09 nmbd.log
samba的安全级别:
share: 不用验证可以匿名访问
user :需要身份验证,需要samba账号库
server :需要其他服务器进行身份验证
domain :域 DC进行验证
1.user :需要身份验证,需要samba账号库
104 security = user #安全级别为user,需要输入用户名和密码
105 passdb backend = tdbsam
293 [public] #公共
294 comment = Public dirctory
295 path = /abc #目录
296 public = yes
297 writable = yes
298 printable = yes #共享是打印机形式
299 browsable=yes
300 guest ok=yes
301 write list = +staff
300 [tom]
302 comment = tom directory
304 path = /tom
306 browseable = yes
308 guest ok = no
310 writable = yes
312 valid users = tom
2.添加用户
root@localhost samba]# useradd tom
增加samba 账号数据库
[root@localhost ~]# smbpasswd -a tom #添加为smb用户
修改 tom目录的所有者,所属组为tom
[root@localhost tom]# chown -R tom /tom
[root@localhost tom]# ll
总计 4
-rw-r--r-- 1 tom root 9 12-20 07:31 tom.txt
重启smb
搜索如下:
输入用户名和密码
注意:输入一次后系统会有记录,下次就不需要用户和密码,重启以后就会再次要求输入用户和密码
2.linux samba 客户端访问linux samba 服务器
[root@localhost ~]# smbclient //192.168.10.10/tom -U tom
1.在linux samba客户端手动挂载 把服务器上的共享文件挂到挂载点上
创建挂载点
[root@localhost ~]# mkdir /mnt/smb
[root@localhost ~]# mount -t cifs //192.168.10.10/tom /mnt/smb -o user=tom%123
#%后面是tom的密码
查看如下:
[root@localhost ~]# mount
//192.168.10.10/tom on /mnt/smb type cifs (rw,mand)
[root@localhost ~]# cd /mnt/smb
[root@localhost smb]# ll
总计 4
-rw-r--r-- 1 506 root 9 12-20 02:31 tom.txt 已经挂载上了
2.设置开机启动挂载
[root@localhost ~]# vim /etc/fstab
etc/fstab文件对所有用户可见,用户名和密码不安全。
下面将用户名密码写入一个普通文件,修改其权限,使文件设置为对其他用户不可见。
//192.168.10.10/tom /mnt/smb cifs defaults,credentials=/etc/samba/u1.txt 0 0
创建文件/etc/samba/u1.txt
[root@localhost ~]# vim /etc/samba/u1.txt
username=tom
password=123
修改权限如下:
[root@localhost ~]# chmod 600 /etc/samba/u1.txt
执行命令mount -a 自动挂载文件系统表,或者重启系统
[root@localhost ~]# mount -a
使用mount命令查看是否挂载
自动挂载配置(nfs linux与linux之间的共享)
如果客户端开机挂载后,而没有使用,则将一直和samba服务器相连,消耗服务器资源,因此,可以使用自动挂载,当切换到/mnt/smb下时,自动挂载,退出时,自动取消挂载。
1.编辑/etc/auto.master
[root@localhost ~]# vim /etc/auto.master
[root@localhost ~]# cp /etc/auto.misc /etc/auto.samba
[root@localhost ~]# vim /etc/auto.samba
server -fstype=cifs,username=tom,password=123 ://192.168.10.10/tom
重启autofs 服务
[root@localhost ~]# service autofs restart
停止 automount: [确定]
启动 automount: [确定]
注意:由于前面做的已经挂载上了而且不好卸载,为了验证,可以把/etc/fstab 里面的配置注销掉 重启测试
[root@localhost ~]# cd /mnt/smb/server
切换到其他目录,等30秒会发现 自动取消挂载。
再次切换到/mnt/smb/server 下就会再次自动挂载。很是智能。