centos7.4安装samba服务
centos7.4安装samba服务匿名访问samba服务器
查看windows所属的工作组,修改hosts文件(客户端 192.168.221.1的配置)
C:\Users\Administrator>net config workstation
notepad C:\Windows\System32\drivers\etc\hosts
192.168.221.20 apenglinux-002//共享服务器ip与主机名
samba服务器(192.168.221.20)安装关于samba的一些服务
# yum install samba samba-client samba-common -y
配置/etc/samba/smb.conf
# cd /etc/samba/
# cp smb.conf smb.conf.bak
# vim smb.conf
workgroup = workgroup
server string = Samba Server %v
netbios name = apenglinux-002
security = user
map to guest = bad user
dns proxy = no
comment = This is a directory of anonymous.
path = /samba/anonymous
browseable = yes
writeable = yes
guest ok = yes
read only = no
创建共享目录,并开启服务
# mkdir -p /samba/anonymous
# systemctl enable smb.service
# systemctl enable nmb.service
# systemctl start smb.service
# systemctl start nmb.service
firewalld放行samba
# firewall-cmd --permanent --zone=public --add-service=samba
# firewall-cmd --reload
在windows客户端上访问共享\\apenglinux-002
http://i2.运维网.com/images/blog/201803/30/737df463bbf5922ca7dcaf1e1b26456d.png
设置共享目录的本地权限,属主,属组
# cd /samba/
# chmod 777 anonymous/
# chown -R nobody:nobody anonymous/
再次访问还是与上图一样没有权限
此时需要设置selinux
# chcon -t samba_share_t anonymous/
此时就可以访问共享了,并可以在共享目录下创建文件了
http://i2.运维网.com/images/blog/201803/30/7b026281c219cf21ffb546b3eebfd65a.png
通过用户名密码访问samba服务器
创建组和用户通过认证来访问samba服务器
# groupadd smbgrp
# useradd -s /sbin/nologin smbusr
# usermod -a smbusr -G smbgrp
# smbpasswd -a smbusr
创建共享目录,设定权限
# mkdir -p /samba/security
# chmod 777 /samba/security
# chown -R smbusr:smbgrp /samba/security/
修改配置文件
# vim /etc/samba/smb.conf
path = /samba/security
valid users = @smbgrp
guest ok = no
writeable = yes
browseable = yes
重启服务,测试
# systemctl restart smb.service
# systemctl restart nmb.service
# testparm
设置selinux
# chcon -t samba_share_t /samba/security/
在windows客户端访问\\apenglinux-002\securiy
http://i2.运维网.com/images/blog/201803/30/29eba939d3f7394e668cbeba9051ad47.png
linux客户端访问
# yum install samba-client -y
# smbclient -L 192.168.221.20 -U smbusr%123
Domain= OS= Server=
Sharename Type Comment
--------- ---- -------
anonymous Disk This is a directory of anonymous.
security Disk
IPC$ IPC IPC Service (Samba Server 4.6.2)
Domain= OS= Server=
Server Comment
--------- -------
Workgroup Master
--------- -------
WORKGROUP APENGLINUX-002
# smbclient //samba服务器ip/共享目录 -U 用户名%密码
补充:
vim /etc/samba/smb.conf
security = user//用户需要认证才能访问共享资源
map to guest = bad user //将匿名用户映射为nobody用户
guest user = nobody
server string = Samba Server Version %v //服务器说明
comment = //注释说明
path = //共享目录
writeable = yes|no//
guest ok = yes|no
browseable = yes|no
security = share //不需要用户名密码直接访问
workgroup =
hosts allow = //allow优先级高于deny
hosts deny = 192.168.0.
valid users =
write list = 用户名,@组名
netbios name =
log file = /var/log/samba/log.%m
read only = yes|no
passdb backend = smbpasswd
smb passwd file = /etc/samba/smbpasswd
config file = /etc/samba/smb.conf.%U
# cp /etc/samba/smb.conf /etc/samba/smb.conf.manager
# vim /etc/samba/smb.conf // 加上 browseable = no
# vim /etc/samba/smb.conf.manager // browseable = yes
linux客户端挂载共享目录
# yum install cifs-utils -y
# mount -t cifs //192.168.221.10/boss/ /cifs/ -o username=boss//输入密码
# mount -t cifs //192.168.221.10/boss/ /cifs/ -o username=boss,password=123
http://i2.运维网.com/images/blog/201803/30/f5cd29701b77e11419d0dec747e7dfd6.png
http://i2.运维网.com/images/blog/201803/30/9c349fc00929f1d5cbf327c68da2df11.png
http://i2.运维网.com/images/blog/201803/30/78551c64aecc86e0d581206f7e1439a7.png
页:
[1]