Linux如何啟動(dòng)SELinux
Linux啟動(dòng)SELinux
centos
centos自帶SELinux。
檢查SELinux是否開啟
root@ubuntu:/home/wenyao/Desktop# getenforce Permissive #如果是disabled證明是未開啟,而(enforcing,permissive,不同模式)證明已經(jīng)開啟
開啟
先編輯/etc/selinux/config配置信息
- 強(qiáng)制模式
SELINUX=enforcing:表示所有違反安全策略的行為都將被禁止。 - 寬容模式
SELINUX=permissive:表示所有違反安全策略的行為不被禁止,但是會(huì)在日志中作記錄。
# 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(測(cè)試一般是permissive模式,會(huì)有警告提醒) 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
在根目錄下創(chuàng)建隱藏文件.autorelabel,然后重啟Linux
#新建標(biāo)志文件 touch /.autorelabel #重啟 reboot
驗(yàn)證
#查看模式 root@ubuntu:/home/wenyao/Desktop# getenforce #查看SELinux狀態(tài) root@ubuntu:/home/wenyao/Desktop# sestatus
切換SELinux模式
模式切換不需要重啟linux,而在關(guān)閉SELinux(設(shè)為disabled)或開啟(設(shè)為permissive,Enforcing)需要重啟Linux。
#將 SELinux 在 Enforcing 與 permissive 之間切換(不需要重啟) #0 : 轉(zhuǎn)成permissive 寬容模式 #1 : 轉(zhuǎn)成Enforcing 強(qiáng)制模式 #切換為寬容模式 setenforce 0 #想關(guān)閉只能去改配置文件/etc/selinux/config(需要重啟) vim /etc/selinux/config
Utunbu
安裝SELinux,Utunbu似乎不是自帶SELinux的,而是使用AppArmor代替。
本人在Utunbu20.4測(cè)試,發(fā)現(xiàn)只有AppArmor,所以我需要使用SELinux進(jìn)行替換。
安裝SELinux
#暫停apparmor sudo systemctl stop apparmor #卸載apparmor sudo apt purge apparmor #更新apt源 sudo apt update #安裝SELiunx需要的包 sudo apt install policycoreutils selinux-utils selinux-basics #驗(yàn)證安裝成功(會(huì)被告知你需要重啟) sudo selinux-activate #重啟 reboot
開啟
也是/etc/selinux/config配置信息,會(huì)發(fā)現(xiàn)跟centos那邊的SELinux的配置文件有一些些不同,不過主題內(nèi)容大致一致。
# 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. #默認(rèn)是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
驗(yàn)證
驗(yàn)證方式?jīng)]改變
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一樣。
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Linux高并發(fā)服務(wù)器實(shí)現(xiàn)原理詳解
在互聯(lián)網(wǎng)應(yīng)用爆炸式增長的今天,服務(wù)器需要同時(shí)處理成千上萬的客戶端連接已成為常態(tài),本文將帶您深入探索Linux環(huán)境下高并發(fā)服務(wù)器的實(shí)現(xiàn)原理,從傳統(tǒng)的多進(jìn)程/多線程模型,到現(xiàn)代的多路IO轉(zhuǎn)接機(jī)制,需要的朋友可以參考下2026-03-03
Centos8搭建本地Web服務(wù)器的實(shí)現(xiàn)步驟
這篇文章主要介紹了Centos8搭建本地Web服務(wù)器的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01
centos7 mysql數(shù)據(jù)庫安裝和配置
本篇文章主要介紹了centos7 mysql數(shù)據(jù)庫安裝和配置 ,非常具有實(shí)用價(jià)值,希望對(duì)大家實(shí)用mysql能夠有所幫助2017-01-01
Linux系統(tǒng)之時(shí)間同步實(shí)現(xiàn)方法
本文系統(tǒng)介紹了NTP、ntpdate和chrony三種時(shí)間同步工具的使用方法,包括安裝、配置、啟動(dòng)、狀態(tài)檢查及同步失敗處理,同時(shí)涵蓋手動(dòng)調(diào)整時(shí)間、同步硬件時(shí)間與設(shè)置時(shí)區(qū)的操作步驟2025-08-08

