个人学习使用
cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
----------------------------------------------------------------------
getenforce
Enforcing
----------------------------------------------------------------------
systemctl status firewalld.service
Active: active (running)
----------------------------------------------------------------------
systemctl status NetworkManager
Active: active (running)
1)参数
1.1)配置文件
comment = 任意字符串
说明:comment是对该共享的描述,可以是任意字符串
----------------------------------------------------------------------
path = 共享目录路径
说明:path用来指定共享目录的路径
----------------------------------------------------------------------
browseable = yes/no
说明:browseable用来指定该共享是否可以浏览
----------------------------------------------------------------------
writable = yes/no
说明:writable用来指定该共享路径是否可写
----------------------------------------------------------------------
available = yes/no
说明:available用来指定该共享资源是否可用
----------------------------------------------------------------------
admin users = 该共享的管理者
说明:admin users用来指定该共享的管理员(对该共享具有完全控制权限)在samba 3.0中,如果用户验证方式设置成“security=share”时,此项无效
例如:admin users =bobyuan,jane(多个用户中间用逗号隔开)
----------------------------------------------------------------------
valid users = 允许访问该共享的用户
说明:valid users用来指定允许访问该共享资源的用户
例如:valid users = bobyuan,@bob,@tech(多个用户或者组中间用逗号隔开,如果要加入一个组就用“@+组名”表示)
----------------------------------------------------------------------
invalid users = 禁止访问该共享的用户
说明:invalid users用来指定不允许访问该共享资源的用户
例如:invalid users = root,@bob(多个用户或者组中间用逗号隔开)
----------------------------------------------------------------------
write list = 允许写入该共享的用户
说明:write list用来指定可以在该共享下写入文件的用户
例如:write list = bobyuan,@bob
----------------------------------------------------------------------
public = yes/no
说明:public用来指定该共享是否允许guest账户访问
----------------------------------------------------------------------
guest ok = yes/no
说明:意义同“public”
1.2)用户管理
pdbedit -a username
说明:新建Samba账户
----------------------------------------------------------------------
pdbedit -r username
说明:修改Samba账户
----------------------------------------------------------------------
pdbedit -x username
说明:删除Samba账户
----------------------------------------------------------------------
pdbedit -L
说明:列出Samba用户列表,读取passdb.tdb数据库文件
----------------------------------------------------------------------
pdbedit -Lv
说明:列出Samba用户列表详细信息
----------------------------------------------------------------------
pdbedit -c “[D]” -u username
说明:暂停该Samba用户账号
----------------------------------------------------------------------
pdbedit -c “[]” -u username
说明:恢复该Samba用户账号
2)安装
2.1)安装
yum install -y samba
2.2)防火墙
firewall-cmd --add-service samba --permanent
success
说明:添加samba服务到防火墙策略中
----------------------------------------------------------------------
firewall-cmd --reload
success
说明:重启防火墙
----------------------------------------------------------------------
firewall-cmd --list-all|grep samba
services: ssh dhcpv6-client samba
说明:查看samba服务是否添加到防火墙中
2.3)SELINUX
setsebool -P samba_export_all_rw on
说明:开启永久读写权限
getsebool -a |grep samba
说明:查找关于samba的权限
2.4)Samba服务配置
vim /etc/samba/smb.conf
----------------------------------------------------------------------
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
[fenxiang]
path = /data/samba
public = no
valid users = liyiyi,@samba
printable = no
write list = liyiyi
2.5)创建共享目录
mkdir -p /data/samba
chown -R samba.samba /data/samba
ll -d /data/samba/
drwxr-xr-x. 5 samba samba 60 Dec 20 14:52 /data/samba/
----------------------------------------------------------------------
chcon -t samba_share_t /data/samba
说明:更改SELINUX标签
2.6)添加samba账号
useradd -d /data/samba -s /sbin/nologin liyiyi
说明:
-d:指定用户登入时的主目录
-s:指定用户登入后所使用的shell
----------------------------------------------------------------------
pdbedit -a -u liyiyi
new password:
retype new password:
----------------------------------------------------------------------
pdbedit -L
说明:查看samba账号列表
liyi:1003:
2.7)共享目录授权
setfacl -m u:用户名:rwx /目标目录
3)定时任务更新权限
3.1)编写脚本
vim /opt/samba_quanxian.sh
----------------------------------------------------------------------
#!/bin/bash
chomd -R 700 /data/samba
chown -R liyiyi.liyiyi /data/samba
setfacl -m u:liyiyi:rwx /data/samba
----------------------------------------------------------------------
chmod +x /opt/samba_quanxian.sh
3.2)编写定时任务
每分钟执行一次
crontab -e
----------------------------------------------------------------------
*/1 * * * * /opt/samba_quanxian.sh