CentOS7關閉SELINUX

CentOS7關閉SELINUX

在 Linux 進行軟體安裝時,幾乎都會關閉 SELinux。
SELinux(Security-Enhanced Linux)是為了避免使用者資源的誤用,在進行程序、檔案等細部權限設定依據的一個核心模組!
遵從最小權限理念,預設情況下所有程序都是被拒絕的。

SELinux 共有三種模式如下:

Enforcing:強制模式,依據設定來限制檔案資源存取。
Permissive:寬容模式,不限制檔案資源存取,但仍會依據設定檢查並記錄相關訊息。
Disabled:停用模式,SELinux 已被停用。

使用指令可以查詢目前模式。

1
$ getenforce

使用指令可以檢視 SELinux 詳細狀態。

1
$ sestatus

針對SELINUX執行指令如下:

1
2
3
4
5
6
7
8
$ setenforce 0
$ sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
$ systemctl disable firewalld
$ systemctl disable NetworkManager
$ yum -y install iptables-utils iptables-services
$ iptables -F
$ iptables -X
$ service iptables save

reference:

★★ 暫時性的關掉或開啟 selinux ★★

1
2
3
4
5
6
7
8
$ getenforce
Enforcing
$ sudo setenforce 0
$ getenforce
Permissive
$ sudo setenforce 1
$ getenforce
Enforcing

★★ 永久性的關掉 selinux ★★

使用指令檢視設定檔內容。

1
$ sudo vi /etc/sysconfig/selinux    

找到
SELINUX=enforcing
然後修改為
SELINUX=disabled
要重新開機 reboot / restart 後才會套用