
samba是linux上的文件共享服务软件,相当与Windows上的共享文件夹,当然也是要在同一网段上的。
当前用的版本是4.4.4,好吧!下面介绍怎么去安装配置它,here we go!
1. 安装:
[root@localhost ~]# yum install samba samba-client samba-common
2. 创建可访问的用户:
[root@localhost SMBShare]# groupadd smbgrp --> 创建一个可访问的用户组smbgrp
[root@localhost SMBShare]# useradd -G smbgrp smbtest --> 创建一个用户并把他加入到smbgrp组中
[root@localhost SMBShare]# smbpasswd -a smbtest --> 把这个用户添加到samba的访问列表中
New SMB password:
Retype new SMB password:
Added user smbtest.
3. 创建共享目录:
[root@localhost ~]# mkdir /home/SMBShare/ -->创建共享目录SMBShare
[root@localhost SMBShare]# chmod -R 0777 /home/SMBShare/ -->把目录的读写权限更改成可读写执行
[root@localhost SMBShare]# chown -R smbtest:smbgrp /home/SMBShare/ -->把文件拥有者改为smbtest账户和smbgrp组
[root@localhost SMBShare]# chcon -t samba_share_t /home/SMBShare/ -->允许匿名用户可访问上传文件
4. 修改配置文件smb.conf 并保存:
先把原来的配置文件备份一下
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
然后编辑配置文件
vi /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = centos
security = user
map to guest = bad user
dns proxy = no
[mobile]
path = /home/SMBShare
valid users = @smbgrp
guest ok = no
writeable = yes
browsable = yes
5. 启用服务:
systemctl restart smb.service
6. 防火墙设置:
因为我仅仅是为了实验所以就把防火墙关掉了 #systemctl disable firewalld.service
当然也可以设置例外 #firewall-cmd --permanent --zone=public --add-service=samba
重新加载防火墙 #firewall -cmd --reload
6. 访问测试:
在windows上输入 \\ip地址, 然后输入帐号:smbtest 密码:*********
tip:
设置匿名共享:
mkdir /samba/anonymous
chown -R nobody:nobody /samba/anonymous
chmod -R 0755 /samba/anonymous
chcon -t samba_share_t /samba/anonymous
smb.conf文件中加入以下字段:
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = centos
security = user
map to guest = bad user
dns proxy = no
[Anonymous]
path = /samba/anonymous
browsable =yes
writable = yes
guest ok = yes
read only = no