查看SELinux状态&关闭SELinux

1. 查看SELinux状态

1.1 getenforce
  • getenforce 命令是单词get(获取)和enforce(执行)连写,可查看selinux状态,与setenforce命令相反。
  • setenforce 命令则是单词set(设置)和enforce(执行)连写,用于设置selinux防火墙状态,如: setenforce 0用于关闭selinux防火墙,但重启后失效

    [root@localhost ~]# getenforce
    Enforcing
1.2 /usr/sbin/sestatus

Current mode表示当前selinux防火墙的安全策略

[root@localhost ~]# /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:      28

SELinux status:selinux防火墙的状态,enabled表示启用selinux防火墙
Current mode: selinux防火墙当前的安全策略,enforcing 表示强

2. 关闭SELinux

2.1 临时关闭

setenforce 0 :用于关闭selinux防火墙,但重启后失效。

[root@localhost ~]# setenforce 0
[root@localhost ~]# /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:      28
2.1 永久关闭

修改selinux的配置文件,重启后生效。

打开 selinux 配置文件
[root@localhost ~]# vim /etc/selinux/config
修改 selinux 配置文件

将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=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,配置文件并未生效。

[root@localhost ~]# getenforce
Enforcing
重启
[root@localhost ~]# reboot
验证
[root@localhost ~]# /usr/sbin/sestatus
SELinux status:                 disabled

[root@localhost ~]# getenforce
Disabled
<think>好的,用户想检查SELinux状态,我需要根据提供的引用资料来回答。首先,用户的问题是关于如何验证SELinux状态,所以应该集中在检查状态的方法上。 根据引用[1]和[3],提到查看状态的方法有两种:使用`sestatus`命令和检查配置文件`/etc/selinux/config`。另外,引用[4]中的配置文件示例显示SELINUX=permissive,这也是一种查看方式。可能还可以用`getenforce`命令快速获取当前模式,虽然引用中没有直接提到,但常见做法中这是标准命令,应该补充进去。 需要确保步骤清晰,分点说明。比如第一步使用`sestatus`,第二步用`getenforce`,第三步检查配置文件。还要解释输出结果的含义,比如Enforcing、Permissive、Disabled的区别,这部分在引用[2]和[5]中有说明,可以引用。 另外,注意用户可能需要知道每种模式的含义,所以解释每个状态的作用和影响是必要的,这样用户不仅知道如何检查,还能理解结果的意义。比如Enforcing是强制执行策略,Permissive只记录不阻止,Disabled是完全关闭,这些在引用[2]和[5]中有详细说明。 还要注意是否需要root权限来执行这些命令,比如`sestatus`可能需要安装或特定权限,但通常这些命令普通用户也可以运行。不过如果用户遇到问题,可能需要提示安装相关工具,比如通过`yum install policycoreutils`来获取`sestatus`,但引用中没有提到,所以可能不需要包含,除非确定。 最后,生成相关问题时要围绕SELinux状态检查扩展,比如如何临时更改模式、永久配置、禁用影响等,这些问题在引用中都有涉及,可以合理提出。</think>### 如何验证SELinux状态 #### 方法1:使用 `sestatus` 命令 1. 打开终端,输入以下命令: ```bash sestatus ``` 2. 输出结果示例: ``` SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: default Current mode: enforcing Mode from config file: enforcing ``` - **关键字段**: - `SELinux status`:显示是否启用(`enabled`或`disabled`)。 - `Current mode`:当前运行模式(`enforcing`、`permissive`或`disabled`)[^1][^4]。 #### 方法2:使用 `getenforce` 命令 1. 输入以下命令快速获取当前模式: ```bash getenforce ``` 2. 输出结果示例: ``` Enforcing ``` 直接显示当前模式(`Enforcing`、`Permissive`或`Disabled`)[^3]。 #### 方法3:检查配置文件 1. 查看 `/etc/selinux/config` 文件: ```bash cat /etc/selinux/config ``` 2. 关键字段 `SELINUX=`: ```bash SELINUX=enforcing # 可能值为 enforcing、permissive 或 disabled ``` 此配置决定系统重启后的默认模式,需重启生效[^2][^4]。 #### 模式说明 1. **Enforcing**:强制执行安全策略,阻止未授权操作。 2. **Permissive**:仅记录违规行为,不阻止操作(调试用)。 3. **Disabled**:完全禁用SELinux,内核不再加载相关模块[^2][^5]。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值