您的位置:首页 > Web前端

Fedora 20下配置samba服务器

2015-01-16 14:12 351 查看
1 安装samba

[root@localhost ~]# yum –y install samba ← 通过网络安装samba

yum -y install samba-client //客户端和一些管理工具,包含smbpasswd

2 添加samba用户(用户名称叫“samba”)

[root@localhost ~]# adduser samba ← 添加用户samba(系统自动在/home下创建samba文件夹)

[root@localhost ~]# smbpasswd -a samba ← 将系统用户samba加入到 samba 用户数据库

New SMB password: ← 输入该用户用于登录 samba 的密码

Retype new SMB password: ← 再次确认输入该密码

3 配置samba

[root@localhost ~]# cd /etc/samba/ ← 进入samba配置目录

[root@localhost ~]# cp smb.conf smbbak.conf ← 修改samba配置文件之前,首先对其进行备份(一个好习惯)

[root@localhost ~]# vi /etc/samba/smb.conf ← 打开配置文件

需要修改:

workgroup = WORKGROUP //设置工作组 security = share //安全级别,user需要用户名和密码,share级别则不要

需要添加:

[jimmy] //建立一个共享名为jimmy的共享,名字随意,但是后面windows下会用到 comment = Samba //描述信息,同样随意

path = /home/jimmy/share //共享路径,需要有访问权限

public = yes //是否允许guest用户访问(相当于guest ok = yes/no)

writable = yes //是否可写

创建共享目录:

mkdir /home/jimmy/share

分配权限:

chmod 777 /home/jimmy/share

我的在配置文件的最后加入下列内容:(个人设置)

[samba]

comment = samba ← samba描述

path = /home/samba ← 共享目录

public = no ← 是否允许guest用户访问(相当于guest ok = yes/no)

writable = yes ← 是否可写

browseable = yes ← 是否允许浏览(该行可以不写)

valid users = @samba ← 访问用户(可以有多个,如:@samba @testuser ……)

4 开放防火墙端口

[root@localhost ~]# cd /etc/sysconfig/ ← 进入防火墙配置目录

[root@localhost ~]# cp iptables iptablesbak ← 修改端口配置文件之前,首先对其进行备份(一个好习惯)

[root@localhost ~]# vi /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

[root@sample ~]# /etc/rc.d/init.d/iptables restart ← 重新启动iptables,使新的规则生效

Flushing firewall rules:           [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules:        [ OK ]
Applying iptables firewall rules:      [ OK ]

或者

关闭防火墙 //不关的后果是windows看不到本机

systemctl stop firewalld //暂时关闭防火墙

systemctl disable firewalld //开机禁止启动

5 启动samba服务(含两个守护进程:smb nmb

[root@localhost /]# systemctl restart smb.service nmb.service

6 关闭selinux

[root@localhost /]# vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled //修改为disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

7 查看Fedora是否安装Samba成功

[root@localhost /]# rpm -qa |grep samba

samba-libs-4.1.14-1.fc20.i686
samba-client-4.1.14-1.fc20.i686
samba-4.1.14-1.fc20.i686
samba-common-4.1.14-1.fc20.i686

出现以上信息说明Samba安装成功

[b]8 测试samba[/b]


打开windows运行 \\(linux的ip地址)\(smb.conf中添加的共享名)

如:\\192.168.2.146\samba



可能会提示没有权限或者无法访问,这是因为selinux对samba共享做了限制,所以个人采取关闭selinux.(若提示"找不到***,请检查拼写"关闭防火墙才行 #service iptables stop)



关闭方法:打开/etc/selinux/config



修改:SELINUX=disable 重启linux生效

ok了剩下的就是windows下映射网络驱动器啦,小case的对吧

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: