1. 程式人生 > 實用技巧 >SELinux 寬容模式(permissive) 強制模式(enforcing) 關閉(disabled)

SELinux 寬容模式(permissive) 強制模式(enforcing) 關閉(disabled)

SElinux共有3中狀態。
1、selinux的配置檔案:/etc/selinux/config
# This file controls the state of SELinux on the system.
3 # SELINUX= can take one of these three values:
4 # enforcing - SELinux security policy is enforced.
5 # permissive - SELinux prints warnings instead of enforcing.
6 # disabled - No SELinux policy is loaded.
7 SELINUX=permissive
8 # SELINUXTYPE= can take one of three two values:
9 # targeted - Targeted processes are protected,
10 # minimum - Modification of targeted policy. Only selected processes are protected.
11 # mls - Multi Level Security protection.
12 SELINUXTYPE=targeted

enforcing:強制模式,代表 SELinux 運作中,且已經正確的開始限制 domain/type 了; permissive:寬容模式:代表 SELinux 運作中,不過僅會有警告訊息並不會實際限制 domain/type 的存取。這種模式可以運來作為 SELinux 的 debug 之用;
disabled:關閉,SELinux 並沒有實際運作。
2、檢視現在selinux的狀態:
sestatus
3、永久改變selinux的狀態,需要重新開機,因為,selinux是整合到核心的模組。
4、臨時關閉selinux:setenforce 0
5、臨時開啟,由permissive轉enforcing:setenforce 1
6、使用sed命令修改selinux的配置檔案:
sed-i'/SELINUX/s/enforcing/disabled/'/etc/selinux/config
解說:/SELINUX/為包含匹配以//內字元的行
s為替換命令
sed -i 表示直接修改原始檔,沒有-i只是把修改輸出到標準輸出,並不修改原始檔。
s/要查詢的字串/改後的字串/
注意,整個命令要用單引號引起來。
最後跟上檔名

轉自:
https://www.cnblogs.com/litifeng/p/6939730.html