1、安装samba服务
sudo apt-get install samba
2、添加samba用户
sudo useradd username
编辑用户密码
sudo smbpasswd -a username
删除用户
sudo smbpasswd -x username
3、修改smb.conf配置文件
sudo vim /etc/samba/smb.conf
在最后添加如下内容:
[Share]
comment = Share Folder
path = /home/Jacky/Desktop/samba
browseable = yes
writable = yes
4、重新启动samba服务
sudo /etc/init.d/samba restart
5、在windows中访问samba服务器
注意:
1)、关于selinux,请关闭selinux,在/etc/selinux/config中设置selinux为disabled。
2)、关于firewall设定:
详细可参考samba官网:http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/securing-samba.html#firewallports
Using a Firewall
Many people use a firewall to deny access to services they do not want exposed outside their network. This can be a good idea, although I recommend using it in conjunction with the above methods so you are protected even if your firewall is not active for some reason.
If you are setting up a firewall, you need to know what TCP and UDP ports to allow and block. Samba uses the following:
| Port 135/TCP - used by smbd |
| Port 137/UDP - used by nmbd |
| Port 138/UDP - used by nmbd |
| Port 139/TCP - used by smbd |
| Port 445/TCP - used by smbd |
The last one is important because many older firewall setups may not be aware of it, given that this port was only added to the protocol in recent years.
When configuring a firewall, the high order ports (1024-65535) are often used for outgoing connections and therefore should be permitted through the firewall. It is prudent to block incoming packets on the high order ports except for established connections.
修改/etc/sysconfig/iptables
-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
-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
(说明:在httpd服务中,需开启80端口,开启方法添加如下一行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT)
重启防火墙服务
service iptables restart
或/etc/rc.d/init.d/iptables restart
重启samba服务
/etc/rc.d/init.d/smb restart
本文详细介绍如何在Linux系统上安装并配置Samba服务,包括安装Samba、添加及管理用户、配置smb.conf文件、设置防火墙规则等步骤,帮助读者实现Linux与Windows之间的文件共享。
587

被折叠的 条评论
为什么被折叠?



