CentOS 安装Samba

环境

  • CentOS 7.8

目标需求

在/home目录之外建立一个共享文件夹,新建samba用户组及用户,Samba用户不能登录服务器。共享文件夹中每个samba用户有自己的目录,且可以在自己目录中读写,在他人目录中只可读。

 

建立共享文件夹

[du@langchao ~ 09:15:53]$ sudo mkdir /share_space/samba_share

关闭防火墙和SELinux(安装结束后再打开)

# 防火墙
systemctl status firewalld.service #查看防火墙状态
systemctl stop firewalld.service #关闭防火墙
systemctl disable firewalld.service #关闭开机自启动

# 附打开防火墙命令
systemctl start firewalld.service #打开防火墙
systemctl enable firewalld.service #开机自启动

# SELinux
getenforce #查看SELinux状态
sestatus #获取更多SELinux信息

# 暂时关闭SELinux
setenforce 0

# setenforce 1 设置SELinux 成为enforcing模式
# setenforce 0 设置SELinux 成为permissive模式
# SELINUX=enforcing 强制模式,所有违反安全策略的行为都将被禁止
# SELINUX=permissive 宽容模式,所有违反安全策略的行为不被禁止,但是会在日志中作记录

# 永久关闭SELinux
vim /etc/selinux/config #打开配置文件

# 将SELINUX=enforcing改为SELINUX=disabled
reboot # 重启

[*]新建Samba用户组及Samba用户,Samba用户不允许登录

groupadd samba-user
useradd zxxxxx -M -g samba-user -s /sbin/nologin

安装Samba

yum install samba -y

开启Samba服务

systemctl start smb
service smb start

查看samba服务状态

netstat -antp | grep -E "139|445"
service smb status

[*]添加samba用户

smbpasswd -a zxxxxx # 向smbpasswd文件中添加linux用户

配置conf文件

cp /etc/samba/smb.conf /etc/samba/smb.conf.bak # 备份
vim /etc/samba/smb.conf

=================================== smb.conf ===================================
[global]
config file = /usr/local/samba/lib/smb.conf.%m
workgroup = LC_Samba
log file = /var/log/samba/log.%m
security = user
passdb backend = tdbsam

[samba_share]
comment = 'Samba Server at Langchao'
path = /share_space/samba_share
browseable = yes
writeable=yes
available=yes
admin users=zxxxxx
valid users=@samba-user
public = no
directory mask = 0755
create mask = 0755

重启samba服务

service smb restart

[*]为每位samba用户新建属于自己的文件夹

sudo mkdir /share_space/samba_share/zxxxxx
chown -R zxxxxx:samba-user /share_space/samba_share/zxxxxx

开机自启动

systemctl enable smb.service

打开防火墙和SELinux,并允许Samba服务

# 打开防火墙
systemctl start firewalld.service
systemctl enable firewalld.service

# 开启SELinux
vim /etc/selinuxx/config
SELINUX = enforcing
reboot

# 允许Samba通过防火墙
firewall-cmd --permanent --add-service=samba
firewall-cmd --reload

# 或者
firewall-cmd --zone=public --add-port=139/tcp --permanent
firewall-cmd --zone=public --add-port=445/tcp --permanent
firewall-cmd --zone=public --add-port=137/udp --permanent
firewall-cmd --zone=public --add-port=138/udp --permanent
firewall-cmd --reload
systemctl restart firewalld.service

# SELinux允许Samba
setsebool -P samba_export_all_ro=1
setsebool -P samba_export_all_rw=1
setsebool -P samba_enable_home_dirs=1
chcon -t samba_share_t /share_space/samba_share

其中带有[*]是新增用户时需要进行的操作。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值