SMB协议:实现局域网内文件或者打印机等资源共享服务的协议
Samba服务程序是一款基于SMB协议并由服务端和客户端组成的开源文件共享资源软件,实现了Windows和Linux系统间的文件共享
- 安装Samba服务程序
yum -y install samba
[root@localhost ~]# yum -y install samba
已加载插件:langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
正在解决依赖关系
……
Running transaction
正在安装 : samba-4.1.1-31.el7.x86_64 1/1
验证中 : samba-4.1.1-31.el7.x86_64 1/1
已安装:
samba.x86_64 0:4.1.1-31.el7
完毕!
- 过滤无用的配置文件 比如#$^;
先进行备份
[root@localhost ~]# mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
#过滤无用的配置
[root@localhost ~]# cat /etc/samba/smb.conf.bak | grep -v "#" | grep -v ";" | grep -v "^$" > /etc/samba/smb.conf
cat /etc/samba/smb.conf
#原始配置
[global]
workgroup = MYGROUP
#工作组名称
server string = Samba Server Version %v
#服务器介绍信息
log file = /var/log/samba/log.%m
#定义日志文件存放位置和名称
max log size = 50
#定义日志文件最大容量
security = user
#安全认证的方式,总共有四种
passdb backend = tdbsam
#定义用户后台的类型,总共有三种
load printers = yes
#设置是否当Samba服务启动时共享打印机设备
cups options = raw
#打印机的选项
[homes]
#共享参数
comment = Home Directories
#描述信息
browseable = no
#指定共享是否在“上网邻居”可见
writable = yes
#定义是否写入操作
[printers]
comment = All Printers
path = /var/spool/samba
#共享文件的实际路径
browseable = no
guest ok = no
writable = no
printable = yes
#新添共享名称
[sjc]
comment = "666"
path = /database
public = no
writable = yes
重启smb服务
[root@localhost ~]# systemctl restart smb.service
[root@localhost ~]# systemctl enable smb.service
ln -s ‘/usr/lib/systemd/system/smb.service’ ‘/etc/systemd/system/multi-user.target.wants/smb.service
创建共享文件目录
[root@localhost ~]# mkdir /database
创建Samba独立的账号
[root@localhost ~]# useradd smbuser
[root@localhost ~]# pdbedit -a -u smbuser
new password:
retype new password:
Passwords do not match!
[root@localhost ~]# pdbedit -a -u smbuser
new password:
retype new password:
Unix username: smbuser
NT username:
Account Flags: [U ]
User SID: S-1-5-21-1351343387-3158319975-999397104-1000
Primary Group SID: S-1-5-21-1351343387-3158319975-999397104-513
Full Name:
Home Directory: \localhostsmbuser
HomeDir Drive:
Logon Script:
Profile Path: \localhostsmbuserprofile
Domain: LOCALHOST
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: 三, 06 2月 2036 23:06:39 CST
Kickoff time: 三, 06 2月 2036 23:06:39 CST
Password last set: 二, 27 6月 2017 13:14:37 CST
Password can change: 二, 27 6月 2017 13:14:37 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
使用Windows认证(要求同Samba服务统一网段)
如果出现能登陆,但是不能进入目录 解决办法如下:
[root@localhost ~]# setsebool -P samba_enable_home_dirs on
[root@localhost ~]# semanage fcontext -a -t samba_share_t /database
[root@localhost ~]# restorecon -Rv /database/
使用Linux认证(要求同Samba服务统一网段)
客户端安装 cifs-utils
[root@localhost ~]# yum -y install cifs-utils
已加载插件:langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
正在解决依赖关系
--> 正在检查事务
---> 软件包 cifs-utils.x86_64.0.6.2-6.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
================================================================================
Package 架构 版本 源 大小
================================================================================
正在安装:
cifs-utils x86_64 6.2-6.el7 local 83 k
事务概要
================================================================================
安装 1 软件包
总下载量:83 k
安装大小:174 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : cifs-utils-6.2-6.el7.x86_64 1/1
验证中 : cifs-utils-6.2-6.el7.x86_64 1/1
已安装:
cifs-utils.x86_64 0:6.2-6.el7
完毕!
创建挂载目录
mkdir /database
[root@localhost ~]# vim auth.smb
username=smbuser
password=redhat
domail=MYGROUP
设置权限
[root@localhost ~]# chmod -Rf 600 auth.smb
[root@localhost ~]# vim /etc/fstab
//192.168.10.10/database /database cifs credentials=/root/auth.smb 0 0
[root@localhost database]# mount -a 就可以看到挂载的目录了