Centos安装Samba共享服务器
安装Samba
查看Samba是否已安装
1.# rpm -qa | grep samba
通过yum直接安装Samba服务端和客户端
2.#yum -y install samba samba-client
创建smb登录用户名和密码
3.#smbpasswd -a root
(echo 123;echo 123) | smbpasswd -s -a root
echo -e "123\n123" | smbpasswd -s -a root
4.配置/etc/samba目录下,备份smb.conf文件
#cp smb.conf smb.confbak
#rm -rf smb.conf //删除smb.conf
#vi smb.conf
设置完成后,重启sambag服务即可
#/etc/init.d/smb restart
开始访问ip:
如果还是无法打开下面的弹窗:
估计是开启了防火墙的原因:
service iptables stop
配置开机启动
chkconfig smb on
chkconfig nmb on
设置Samba服务开机自启动
# chkconfig --list | grep smb
# chkconfig --level 35 smb on
# chkconfig --level 35 nmb on
查看Samba服务状态、启动及重启。
# service smb status
# service smb stop
# service smb start
# service smb restart
现在可以实现centos和windows之间文件的任意共享,提高工作效率了
通过shell脚本自动化实现
centos6.8
#!/bin/sh #ifconfig eth0 | grep "inet addr" | awk '{print $2}' | awk -F: '{print $2}' | awk -F. '{print "htxk-"$4}' > /root/samba.pid setenforce 0 yum -y install samba samba-client #echo -e "htxk\nhhly2015" | smbpasswd -s -a root #echo -e "htxk\nhhly2015" | smbpasswd -a root (echo hhly2015;echo hhly2015) | smbpasswd -s -a root mv /etc/samba/smb.conf /etc/samba/smb.conf.bak touch /etc/samba/smb.conf cat > /etc/samba/smb.conf << EOF [global] workgroup = WORKGROUP server string = Samba Server Version %v netbios name = SambaServer log file = /var/log/samba/%m.log max log size = 50 security = user load printers = no printcap name = /dev/null [htxk] path = / writeable = yes browseable = yes EOF #iptables -A INPUT -p tcp -m multiport --dports 139,445 -j ACCEPT #iptables -A INPUT -p udp -m multiport --dports 137,138 -j ACCEPT #iptables -A OUTPUT -p tcp -m multiport --sports 139,445 -j ACCEPT #iptables -A OUTPUT -p tcp -m multiport --sports 137,138 -j ACCEPT #iptables-save sed -i "11s#\[htxk\]#\[$(cat /root/samba.pid)\]#g" /etc/samba/smb.conf /etc/init.d/smb restart service iptables stop
centos7
#!/bin/bash setenforce 0 yum -y install samba samba-client #echo -e "htxk\nhhly2015" | smbpasswd -s -a root #echo -e "htxk\nhhly2015" | smbpasswd -a root (echo hhly2015;echo hhly2015) | smbpasswd -s -a root mv /etc/samba/smb.conf /etc/samba/smb.conf.bak touch /etc/samba/smb.conf cat > /etc/samba/smb.conf << EOF [global] workgroup = WORKGROUP server string = Samba Server Version %v netbios name = SambaServer log file = /var/log/samba/%m.log max log size = 50 security = user load printers = no printcap name = /dev/null [htxk] path = / writeable = yes browseable = yes EOF #iptables -A INPUT -p tcp -m multiport --dports 139,445 -j ACCEPT #iptables -A INPUT -p udp -m multiport --dports 137,138 -j ACCEPT #iptables -A OUTPUT -p tcp -m multiport --sports 139,445 -j ACCEPT #iptables -A OUTPUT -p tcp -m multiport --sports 137,138 -j ACCEPT #iptables-save systemctl stop firewalld systemctl enable smb systemctl enable nmb systemctl start smb systemctl start nmb
作者:Agoly 出处:https://www.cnblogs.com/qmfsun/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 如果文中有什么错误,欢迎指出。以免更多的人被误导。 |