这两天看了看vsftpd的芳邻~NFS和Samba,觉得不能和windows通信的nfs看来是过时了。今天做个桑巴的配置笔记。由于搞vsftpd的时候,跟selinux狠狠地打了一会交道,这次配置samba可谓水到渠成 :xpxiao:
(看了一些如何写博客的文章,我也很想给笔记类的文章配个图,可确实无图可配)
以下内容均以Centos 5.4(Final)版作为实验环境,命令和屏显均为原始数据(有删减)。才疏学浅,如果纰漏请留言指教!
1.安装
两个软件:samba-3.0*和samba-common-3.0*
需要perl-Convert-ASN1支持。
[root@localhost CentOS]# rpm -ivh perl-Convert-ASN1-0.20-1.1.noarch.rpm
warning: perl-Convert-ASN1-0.20-1.1.noarch.rpm: Header V3 DSA signature: NOKEY, key ID e8562897
Preparing… ########################################### [100%]
package perl-Convert-ASN1-0.20-1.1.noarch is already installed[root@localhost CentOS]# rpm -ivh samba-3.0.33-3.14.el5.i386.rpm samba-common-3.0.33-3.14.el5.i386.rpm
warning: samba-3.0.33-3.14.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID e8562897
Preparing… ########################################### [100%]
package samba-common-3.0.33-3.14.el5.i386 is already installed
package samba-3.0.33-3.14.el5.i386 is already installed
2.配置
2.1匿名
做实验用匿名再好不过,我们把/tmp作为共享目录。
配置/etc/samba/smb.conf
[root@localhost CentOS]# vim /etc/samba/smb.conf
workgroup = WORKGROUP
#工作组,windows概念
server string=SMB share server
#服务器名称吧
security = share
#匿名访问
[tmp]
path = /tmp
writeable = yes
browseable = yes
guest ok = yes
每个目录都有这么一块,其中path为路径;writeable可写;browseable可浏览;guest ok以nobody浏览。
注意:这里的可读可写是指定的目录的属性,会忽略目录本身的属性,而不会忽略第二层目录的属性。
比如我这样配置:
[root]
path = /root
writeable = yes
browseable = yes
guest ok = yes
这样nobody可以进入/root,就是说/root对nobody是rwx的,而其下的目录都有自己的属性,这些属性会制约匿名者。
再有,冷博客特意测试了一下,如果guest ok = no的话,windows xp登陆会出现这样的囧态:
根本就没有用户名啥啥的,怎么填呀。
还有就是语系的问题,冷博客这里没有设置语系,windows xp显示中文很正常,打开文本文件除了有msdos和linux不兼容的回车符以外,其他很正常 ,如下:
2.2非匿名
下面来自网络,说的很对,冷博客懒得打字了…
添加samba用户,并设置密码;
我们用的方法是先添加用户,但添加的这些用户都是虚拟用户,因为这些用户是不能通过SHELL登录系统的;另外值得注意的是系统用户密码和Samba用户的密码是不同的。如果您设置了系统用户能登入SHELL,可以设置用户的Samba密码和系统用户通过SHELL登录的密码不同。 冷博客注:用户必须是系统用户、密码可以不同。
我们通过smbpasswd 来添加Samba用户,并设置密码。原理是通过读取/etc/passwd文件中存在的用户名。
[root@localhost sir01]# smbpasswd -a linuxsir
New SMB password: 注:在这里添加Samba用户linuxsir的密码;
Retype new SMB password: 注:再输入一次
这样添加用户的好处是,samba会自动添加到/etc/samba下的smbpasswd和smbusers文件。
然后我们配置/etc/samba/smb.conf
security = user
#使用用户名密码登陆
encrypt passwords = yes
#加密密码
smb passwd file = /etc/samba/smbpasswd
#smb密码文件,这个别错了…
保存重启samba。
Selinux的事情照例放在3节。
3.运行
[root@localhost CentOS]# service smb start
启动 SMB 服务: [确定]
启动 NMB 服务: [确定]
或(一定是启动两个哈~)
[root@localhost CentOS]# smbd;nmbd
selinux有关的设置,如果selinux搞错,出现可以登录不能读取的情况:
samba_domain_controller –> off
samba_enable_home_dirs –> off //如果只在家目录,可以开这个,比下面的全开要安全
samba_export_all_ro –> on //把这个on了,就可以随意访问了
samba_export_all_rw –> off
samba_share_nfs –> off
use_samba_home_dirs –> off
virt_use_samba –> off
在smb.conf中也有相关的说明,很详细,就不翻译了哈~
#—————
# SELINUX NOTES:
#
# If you want to use the useradd/groupadd family of binaries please run:
# setsebool -P samba_domain_controller on
#
#
# If you want to share home directories via samba please run:
# setsebool -P samba_enable_home_dirs on
#
# If you create a new directory you want to share you should mark it as
# "samba-share_t" so that selinux will let you write into it.
# Make sure not to do that on system directories as they may already have
# been marked with othe SELinux labels.
#
# If you create a new directory you want to share you should mark it as
# "samba-share_t" so that selinux will let you write into it.
# Make sure not to do that on system directories as they may already have
# been marked with othe SELinux labels.
#
# Use ls -ldZ /path to see which context a directory has
#
# Set labels only on directories you created!
# To set a label use the following: chcon -t samba_share_t /path
#
# If you need to share a system created directory you can use one of the
# following (read-only/read-write):
# setsebool -P samba_export_all_ro on
# or
# setsebool -P samba_export_all_rw on
# put them into the /var/lib/samba/scripts directory so that smbd will be
# allowed to run them.
最后说一下客户端如何设置:
1.windows xp ,提一下,右键我的电脑-映射网络驱动器
下面的不用罗嗦
2.linux,用smbclient,和ftp的内种互动模式一样
[root@localhost squid-3.1.7]# smbclient ‘\\192.168.1.108\tmp’
Password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.33-3.14.el5]
Server not using user level security and no password supplied.




评论