1、安装samba
检查samba是否已经安装
[root@bak1 ~]# rpm -qa | grep samba
没有任何回显则表示未安装软件包 samba
yum安装samba
[root@bak1 ~]# yum -y install samba samba-client samba-common
再次检查安装结果
[root@bak1 var]# rpm -qa | grep samba
samba-common-libs-4.6.2-12.el7_4.x86_64
samba-common-tools-4.6.2-12.el7_4.x86_64
samba-4.6.2-12.el7_4.x86_64
samba-common-4.6.2-12.el7_4.noarch
samba-client-libs-4.6.2-12.el7_4.x86_64
samba-libs-4.6.2-12.el7_4.x86_64
samba-client-4.6.2-12.el7_4.x86_64
确认安装路径
[root@bak1 var]# whereis samba
samba: /usr/lib64/samba /etc/samba /usr/libexec/samba /usr/share/man/man7/samba.7.gz
2、配置samba
关闭SELINUX
[root@bak1 ~]# vi /etc/sysconfig/selinux
修改下边红字部分
# 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
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
关闭防火墙
[root@bak1 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
如果不关闭防火墙需要开UDP137、UDP138、TCP139、TCP445端口
firewall-cmd --add-port=137/udp --permanent
firewall-cmd --add-port=138/udp --permanent
firewall-cmd --add-port=139/tcp --permanent
firewall-cmd --add-port=445/tcp --permanent
firewall-cmd --reload
重启计算机
[root@bak1 ~]# shutdown -r now
创建共享目录
[root@bak1 home]# mkdir -p /home/share/software
创建共享用户组
[root@bak1 home]# groupadd share
创建共享用户
[root@bak1 home]# useradd -g share -s /sbin/nologin share
注:bak-lt账户专门用于备份Windows系统下的文件
设置共享目录权限
[root@bak1 home]# chown -R share:share /home/share/software
修改共享用户密码
[root@bak1 share]# /bin/smbpasswd -a share
New SMB password:
Retype new SMB password:
Added user share.
修改samba配置文件
[root@bak1 share]# vi /etc/samba/smb.conf
配置文件说明如下:
[global] #全局变量
workgroup = WORKGROUP #工作组
security = user #登陆才可访问共享
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[software] #显示的共享目录名
path = /home/share/software #共享目录路径
comment = Software Directories #共享目录描述
writeable = Yes #共享目录可写入
write list = share #有写入权限的用户
valid users = share #共享目录的用户
browseable = Yes #是否可浏览文件
read only = No #是否只读
inherit acls = No
启动samba服务
systemctl start smb
设置samba服务开机自启动
[root@bak1 share]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.