首先声明:系统为RHEL6或相似的以及以上版本,其他版本没有测试过
1,首先检查是否安装samba软体包即rpm包
- [root@boil ~]# rpm -qa | grep samba
- samba-3.5.10-125.el6.x86_64
samba-client-3.5.10-125.el6.x86_64
samba-common-3.5.10-125.el6.x86_64
samba-winbind-clients-3.5.10-125.el6.x86_64
如果没有安装,你得安装这几个rpm包,当然你的系统是否可以用yum来安装,你的系统yum就要没有问题,不然没有办法安装哦
- [root@boil ~]# yum install samba-*
安装完毕后,我们可以看看samba的配置文件,在之前,我们得备份一下这个文件,不然你修改了很多地方导致你的文件出现错误而无法启动samba服务哦
- [root@boil ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.raw
查看主机名和修改配置文件
- [root@boil ~]# hostname
- boil
- [root@boil ~]# vi /etc/samba/smb.conf
修改几个地方即可
[global]
- workgroup = WORKGROUP ;win7的工作组是WORKGROUP,设置要一致
- server string = Samba Server Version %v
- netbios name = boil ;这里需要与你的主机名一致
我们使用的是user方式,需要密码登陆
- # ----------- 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
在最下面添加
- [public]
- comment = Public Stuff
- path = /public
- browseable = yes
- ; public = yes
- writable = yes
- valid users = @administrator
- write list = administrator
测试
- [root@boil ~]# testparm
新建群组,用户,目录
- [root@boil ~]#/usr/sbin/groupadd administrator
- [root@boil ~]#/usr/sbin/useradd –G administrator administrator
- [root@boil ~]#echo 123456 | passwd –stdin administrator
- [root@boil ~]#mkdir /public
- [root@boil ~]#chown -R administrator.administrator /public
- [root@boil ~]#chmod –R 2770 /public
- [root@boil ~]#pdbedit -L ;查看samba账号信息
增加samba账号
- [root@boil ~]# pdbedit -a –u administrator
- 输入密码
好了,我们再次查看samba信息和开启samba服务
- [root@boil ~]# pdbedit -L
- administrator:503:
- [root@boil ~]# /etc/init.d/smb start ;tcp的端口139和445
- [root@boil ~]# /etc/init.d/nmb start ;udp的的端口137和138
因此我们需要在防火墙中做相应的设置
- [root@boil ~]# netstat -tlunp | grep mbd
- [root@boil ~]# vim /etc/sysconfig/iptables
- #注意:在-A INPUT -j REJECT --reject-with icmp-host-prohibited的上面添加
- -A INPUT -m state --state NEW -m tcp -p tcp --dport 137 -j ACCEPT
- -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 138 -j ACCEPT
- -A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
- [root@boil ~]#/etc/rc.d/init.d/iptables restart
- [root@boil ~]#setsebool -P samba_enable_home_dirs=1 ;这条是因为selinux的原因
OK了,启动->附件->运行->\\localIP
输入账户:administrator 密码:123456
看到你可以共享了吧