Centos安装Samba共享服务器

本文详细介绍如何在CentOS上安装和配置Samba服务,包括安装Samba软件包、设置用户名密码、配置smb.conf文件、开启服务及禁用防火墙等步骤,实现Linux与Windows之间的文件共享。

安装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

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值