Linux如何启动SELinux

 更新时间:2024年02月01日 16:42:21   作者:鸭梨的药丸哥  
这篇文章主要介绍了Linux如何启动SELinux问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

Linux启动SELinux

centos

centos自带SELinux。

检查SELinux是否开启

root@ubuntu:/home/wenyao/Desktop# getenforce
Permissive
#如果是disabled证明是未开启,而(enforcing,permissive,不同模式)证明已经开启

开启

先编辑/etc/selinux/config配置信息

  • 强制模式SELINUX=enforcing:表示所有违反安全策略的行为都将被禁止。
  • 宽容模式SELINUX=permissive:表示所有违反安全策略的行为不被禁止,但是会在日志中作记录。
# 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.
#改为permissive(测试一般是permissive模式,会有警告提醒)
SELINUX=permissive
# 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

在根目录下创建隐藏文件.autorelabel,然后重启Linux

#新建标志文件
touch /.autorelabel
#重启
reboot

验证

#查看模式
root@ubuntu:/home/wenyao/Desktop# getenforce
#查看SELinux状态
root@ubuntu:/home/wenyao/Desktop# sestatus

切换SELinux模式

模式切换不需要重启linux,而在关闭SELinux(设为disabled)或开启(设为permissive,Enforcing)需要重启Linux。

#将 SELinux 在 Enforcing 与 permissive 之间切换(不需要重启)
#0 : 转成permissive 宽容模式
#1 : 转成Enforcing 强制模式
#切换为宽容模式
setenforce 0

#想关闭只能去改配置文件/etc/selinux/config(需要重启)
vim /etc/selinux/config

Utunbu

安装SELinuxUtunbu似乎不是自带SELinux的,而是使用AppArmor代替。

本人在Utunbu20.4测试,发现只有AppArmor,所以我需要使用SELinux进行替换。

安装SELinux

#暂停apparmor
sudo systemctl stop apparmor
#卸载apparmor
sudo apt purge apparmor
#更新apt源
sudo apt update
#安装SELiunx需要的包
sudo apt install policycoreutils selinux-utils selinux-basics
#验证安装成功(会被告知你需要重启)
sudo selinux-activate
#重启
reboot

开启

也是/etc/selinux/config配置信息,会发现跟centos那边的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.
#默认是premissive
SELINUX=permissive
# SELINUXTYPE= can take one of these two values:
# default - equivalent to the old strict and targeted policies
# mls     - Multi-Level Security (for military and educational use)
# src     - Custom policy built from source
SELINUXTYPE=default
# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0

验证

验证方式没改变

root@ubuntu:/home/wenyao/Desktop# getenforce 
Permissive

root@ubuntu:/home/wenyao/Desktop# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             default
Current mode:                   permissive
Mode from config file:          permissive
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     requested (insecure)
Max kernel policy version:      33

切换SELinux模式

跟Centos一样。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • windows apache多端口虚拟主机配置方法

    windows apache多端口虚拟主机配置方法

    有很多朋友喜欢在windows下使用apache作为web服务器,有时候想用非80端口提供服务,因为未备案域名都是封了80端口,提供下载的时候可以用别的端口了,这里简单分享下,方便需要的朋友
    2013-03-03
  • linux之conda环境安装全过程

    linux之conda环境安装全过程

    这篇文章主要介绍了linux之conda环境安装全过程,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-05-05
  • Linux高并发服务器实现原理详解

    Linux高并发服务器实现原理详解

    在互联网应用爆炸式增长的今天,服务器需要同时处理成千上万的客户端连接已成为常态,本文将带您深入探索Linux环境下高并发服务器的实现原理,从传统的多进程/多线程模型,到现代的多路IO转接机制,需要的朋友可以参考下
    2026-03-03
  • Centos8搭建本地Web服务器的实现步骤

    Centos8搭建本地Web服务器的实现步骤

    这篇文章主要介绍了Centos8搭建本地Web服务器的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-01-01
  • centos7 mysql数据库安装和配置

    centos7 mysql数据库安装和配置

    本篇文章主要介绍了centos7 mysql数据库安装和配置 ,非常具有实用价值,希望对大家实用mysql能够有所帮助
    2017-01-01
  • linux使用find和crontab命令定期清理过期文件

    linux使用find和crontab命令定期清理过期文件

    这篇文章主要给大家介绍了linux系统下使用find和crontab命令定期清理过期文件的方法,文中先对find和crontab命令进行了详细的介绍,相信对大家的理解和学习具有一定的参考借鉴价值,下面来一起看看吧。
    2016-12-12
  • .htaccess文件写法之作用范围

    .htaccess文件写法之作用范围

    在htaccess写法详解一文中已经写过了htaccess文件一基本写法和语句原则,同时本文也不再阐述htaccess文件的作用之强大,今天只来讨论一下很多人都容易误解的一个地方,那就是.htaccess文件的作用范围
    2012-02-02
  • Linux chkconfig 命令的使用

    Linux chkconfig 命令的使用

    这篇文章主要介绍了Linux chkconfig 命令的使用,帮助大家更好的理解和学习,感兴趣的朋友可以了解下
    2020-08-08
  • Linux中解除端口占用的方法

    Linux中解除端口占用的方法

    这篇文章主要介绍了Linux中解除端口占用的方法,本例以8080端口被占用为例,通过实例代码给大家介绍,需要的朋友可以参考下
    2019-08-08
  • Linux系统之时间同步实现方法

    Linux系统之时间同步实现方法

    本文系统介绍了NTP、ntpdate和chrony三种时间同步工具的使用方法,包括安装、配置、启动、状态检查及同步失败处理,同时涵盖手动调整时间、同步硬件时间与设置时区的操作步骤
    2025-08-08

最新评论