Linux如何啟動SELinux
Linux啟動SELinux
centos
centos自帶SELinux。
檢查SELinux是否開啟
root@ubuntu:/home/wenyao/Desktop# getenforce Permissive #如果是disabled證明是未開啟,而(enforcing,permissive,不同模式)證明已經(jīng)開啟
開啟
先編輯/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
在根目錄下創(chuàng)建隱藏文件.autorelabel,然后重啟Linux
#新建標志文件 touch /.autorelabel #重啟 reboot
驗證
#查看模式 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 強制模式 #切換為寬容模式 setenforce 0 #想關(guān)閉只能去改配置文件/etc/selinux/config(需要重啟) vim /etc/selinux/config
Utunbu
安裝SELinux,Utunbu似乎不是自帶SELinux的,而是使用AppArmor代替。
本人在Utunbu20.4測試,發(fā)現(xiàn)只有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配置信息,會發(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. #默認是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
驗證
驗證方式?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é)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Linux高并發(fā)服務(wù)器實現(xiàn)原理詳解
在互聯(lián)網(wǎng)應(yīng)用爆炸式增長的今天,服務(wù)器需要同時處理成千上萬的客戶端連接已成為常態(tài),本文將帶您深入探索Linux環(huán)境下高并發(fā)服務(wù)器的實現(xiàn)原理,從傳統(tǒng)的多進程/多線程模型,到現(xiàn)代的多路IO轉(zhuǎn)接機制,需要的朋友可以參考下2026-03-03
Centos8搭建本地Web服務(wù)器的實現(xiàn)步驟
這篇文章主要介紹了Centos8搭建本地Web服務(wù)器的實現(xiàn)步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-01-01
centos7 mysql數(shù)據(jù)庫安裝和配置
本篇文章主要介紹了centos7 mysql數(shù)據(jù)庫安裝和配置 ,非常具有實用價值,希望對大家實用mysql能夠有所幫助2017-01-01

