SELinux的打开 关闭 查询方法

SELinux的基本介绍: https://baike.baidu.com/item/SELinux/8865268?fr=aladdin
在学习部署KafKa 和 zookepeer 文档中遇到的 需要关掉SELinux服务,所以就去查询了SELinux的一些相关操作
enforce(执行)
get(获取)
set(设置)
连写就是命令

在网上查询的 部分用的关于SELinux命令:
(可以参考:查看SELinux状态&关闭SELinux
https://www.linuxidc.com/Linux/2016-11/137723.htm

1.查询

1.1 SELinux 状态命令

getenforce

如果提示 Enforcing 则是 表明 正在运行

[user_1@C5-3 ~]$ getenforce
Enforcing   #表示运行的安全策略强
[user_1@C5-3 ~]$ 

1.2 查看selinux防火墙的安全策略

/usr/sbin/ses

会提示当前selinux的安全策略出来

[root@C5-3 ~]$ /usr/sbin/sestatus
SELinux status:                 enabled      #表示运行
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing    #表示运行的安全策略强
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31

2.关闭SELinux

2.1临时关闭SELinux

setenforce 0   #临时关闭SELinux  重启后失效

这个时候安全策略会进入宽容模式(permissive)

[root@C5-3 ~]$ /usr/sbin/sestatus
SELinux status:                 enabled      #表示运行
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive    #表示运行的安全策略是宽容模式
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31

2.2修改配置文件关闭SELinux

[root@C5-3 ~]$ vim /etc/selinux/config
# 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=enforcing   
# 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

将SELINUX=enforcing改为SELINUX=disabled,保存后退出 ,如下:

# 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

然后 需要重启服务器 reboot

reboot

最后查询就是

[root@C5-3 ~]# getenforce
Disabled

3.打开SELinux

3.1打开SELinux

setenforce 1  # 打开SElinux
注意:配置文件中 将SELINUX的值设置为disabled 并且已经生效了后 这个命令也不能打开
必须要修改配置文件!!

3.2修改配置文件
参考关闭修改配置文件 修改回来 保存 重启

4.关于强制模式、宽容模式、关闭的概念:

1.enforcing:强制模式,代表 SELinux 运作中,且已经正确的开始限制 domain/type 了;
2.permissive:宽容模式:代表 SELinux 运作中,不过仅会有警告讯息并不会实际限制 domain/type 的存取。这种模式可以运来作为 SELinux 的 debug 之用;
3.disabled:关闭,SELinux 并没有实际运作。
(可以参考:SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled)
https://www.cnblogs.com/litifeng/p/6939730.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值