简介
本文只是教你快速的搭建一个可以共享的Samba服务器,如果想深入学习可以看看鸟哥的私房菜服务器架设
安装
samba
这个套件主要包含了 SAMBA 的主要 daemon 档案 (smbd及nmbd)、SAMBA的文件档 (document)、以及其它与SAMBA相关的 logrotate设定文件及开机预设选项档案等
samba-common
这个套件则主要提供了SAMBA的主要设定档 (smb.conf) 、smb.conf语法检验的测试程序testparm等等
samba-client
这个套件则提供了当Linux做为SAMBA Client端时,所需要的工具指令,例如挂载SAMBA档案格式的执行档smbmount等等。
可以用yum install packagename命令进行安装
配置(1)不用密码
修改配置文件
- [root@localhost~]#vi/etc/samba/smb.conf
将smb.conf文件中的
security = user
改为
security = share
[share]
comment = tmp share
path = /share
writeable = yes
browseable = yes
guest ok = yes
创建共享目录并设置权限
- [root@localhost~]#mkdir/share/
- [root@localhost~]#chmod-R01777/share/
防火墙配置
打开/etc/sysconfig/iptables文件,添加如下内容:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 137 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 138 -j ACCEPT
当然了你还可以使用文本界面配置防火墙system-config-firewall-tui不过这样你又少了一次熟悉写防火墙规则的机会了 呵呵
配置SELinux
- [root@localhost~]#chcon-R-tpublic_content_rw_t/share/
- [root@localhost~]#chcon-R-tsamba_share_t/share/
- [root@localhost~]#setseboolsamba_export_all_rwon
如果是/home,还要执行如下命令:
- [root@localhost~]#getsebool-a|grepsamba
- samba_domain_controller-->off
- samba_enable_home_dirs-->off
- samba_export_all_ro-->off
- samba_export_all_rw-->on
- samba_share_nfs-->off
- use_samba_home_dirs-->off
- virt_use_samba-->off
- [root@localhost~]#setseboolsamba_enable_home_dirs1
- 或
- [root@localhost~]#setseboolsamba_enable_home_dirson
设置samba服务器开机自启动
- [root@localhost~]#chkconfig--level35smbon
- [root@localhost~]#chkconfig--level35nmbon
当然了也可以使用ntsysv来配置
配置(2)需要密码
首先修改
security = share
为
security = user
添加共享
[samba]
comment = Linux Samba share
path = /home/samba
public = yes
browseable = yes
writable = yes
guest ok = no
create mask = 0664
directory mask = 0755
添加用户和samba用户
- [root@localhost~]#useraddsamba
- [root@localhost~]#passwdsamba
- [root@localhost~]#smbpasswd-asamba
使用
重启服务:
- [root@localhost~]#servicesmbrestart
- 或
- [root@localhost~]#/etc/rc.d/init.d/smbrestart
- 或
- [root@localhost~]#servicenmbrestart
Linux访问samba共享的资源
打开“文件浏览器”,在地址栏输入:smb://ipaddr
Windows访问samba共享的资源
打开“我的电脑”,在地址栏输入:\\ipaddr
注意:
Windows访问samba的共享资源时,需要将smb.conf文件中下面语句取消注释
;netbios name = MYSERVER
如果一切设置正确,windows仍然无法访问samba的共享资源时,要考虑“计算机名”重名的问题(因为局域网的电脑是网络传系统,设置起初都一样)。