1 Samba文件共享服务
Samba服务程序的配置方法与之前讲解的很多服务的配置方法类似,首先需要先通过Yum软件仓库来安装Samba服务程序(Samba服务程序的名字也恰巧是软件包的名字):
[root@linuxprobe ~ ]# yum install samba
Loaded plugins: langpacks, product-id, subscription-manager
………………省略部分输出信息………………
Installing:
samba x86_64 4.1.1-31.el7 rhel 527 k
Installing : samba-4.1.1-31.el7.x86_64 1/1
Verifying : samba-4.1.1-31.el7.x86_64 1/1
Installed:
samba.x86_64 0:4.1.1-31.el7
Complete!
安装完毕后打开Samba服务程序的主配置文件。
**[root@linuxprobe ~]# cat /etc/samba/smb.conf
This is the main Samba configuration file. For detailed information about the
options listed here, refer to the smb.conf(5) manual page. Samba has a huge
number of configurable options, most of which are not shown in this example.
The Official Samba 3.2.x HOWTO and Reference Guide contains step-by-step
guides for installing, configuring, and using Samba:
http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
The Samba-3 by Example guide has working examples for smb.conf. This guide is
generated daily: http://www.samba.org/samba/docs/Samba-Guide.pdf
In this file, lines starting with a semicolon (; ) or a hash (#) are
comments and are ignored. This file uses hashes to denote commentary and
semicolons for parts of the file you may wish to configure.
Note: Run the “testparm” command after modifying this file to check for basic
syntax errors.
………………省略部分输出信息………………**
由于在Samba服务程序的主配置文件中,注释信息行实在太多,不便于分析里面的重要参数,因此先把主配置文件改个名字,然后使用cat命令读入主配置文件,再在grep命令后面添加-v参数(反向选择),分别去掉所有以井号(#)和分号(;)开头的注释信息行,对于剩余的空白行可以使用^$参数来表示并进行反选过滤,最后把过滤后的可用参数信息通过重定向符覆盖写入到原始文件名称中。
[root@linuxprobe ~]# mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
[root@linuxprobe ~]# cat /etc/samba/smb.conf.bak | grep -v “#” | grep -v “;” | grep -v “^$” > /etc/samba/smb.conf
[root@linuxprobe ~]# cat /etc/samba/smb.conf
1.1 配置共享资源
[root@linuxprobe ~]# id linuxprobe
uid=1000(linuxprobe) gid=1000(linuxprobe) groups=1000(linuxprobe)
[root@linuxprobe ~]# pdbedit -a -u linuxprobe
new password:此处输入该账户在Samba服务数据库中的密码
retype new password:再次输入密码进行确认
Unix username: linuxprobe
NT username:
Account Flags: [U ]
User SID: S-1-5-21-507407404-3243012849-3065158664-1000
Primary Group SID: S-1-5-21-507407404-3243012849-3065158664-513
Full Name: linuxprobe
Home Directory: \localhost\linuxprobe
HomeDir Drive:
Logon Script:
Profile Path: \localhost\linuxprobe\profile
Domain: LOCALHOST
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: Wed, 06 Feb 2036 10:06:39 EST
Kickoff time: Wed, 06 Feb 2036 10:06:39 EST
Password last set: Mon, 13 Mar 2017 04:22:25 EDT
Password can change: Mon, 13 Mar 2017 04:22:25 EDT
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
[root@linuxprobe ~]# mkdir /home/database
[root@linuxprobe ~]# chown -Rf linuxprobe:linuxprobe /home/database
[root@linuxprobe ~]# semanage fcontext -a -t samba_share_t /home/database
[root@linuxprobe ~]# restorecon -Rv /home/database
restorecon reset /home/database context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:samba_share_t:s0
设置SELinux服务与策略,使其允许通过Samba服务程序访问普通用户家目录。执行getsebool命令,筛选出所有与Samba服务程序相关的SELinux域策略,根据策略的名称(和经验)选择出正确的策略条目进行开启即可:
[root@linuxprobe ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
use_samba_home_dirs --> off
virt_sandbox_use_samba --> off
virt_use_samba --> off
[root@linuxprobe ~]# setsebool -P samba_enable_home_dirs on
在Samba服务程序的主配置文件中,根据表12-2所提到的格式写入共享信息。在原始的配置文件中,[homes]参数为来访用户的家目录共享信息,[printers]参数为共享的打印机设备。
[root@linuxprobe ~]# vim /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
cups options = raw
[database]
comment = Do not arbitrarily modify the database file
path = /home/database
public = no
writable = yes
Samba服务程序的配置工作基本完毕。接下来重启smb服务(Samba服务程序在Linux系统中的名字为smb)并清空iptables防火墙,然后就可以检验配置效果了。
[root@linuxprobe ~]# systemctl restart smb
[root@linuxprobe ~]# systemctl enable smb
ln -s ‘/usr/lib/systemd/system/smb.service’ ‘/etc/systemd/system/multi-user.target.wants/smb.service’
[root@linuxprobe ~]# iptables -F
[root@linuxprobe ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]