天天看點

如何在CentOS 8上禁用SELinux

SELinux或Security-Enhanced Linux是提供通路控制安全政策的機制或安全子產品。 簡而言之,它是一項功能或服務,用于将使用者限制為系統管理者設定的某些政策和規則。

在本主題中,您将學習如何臨時禁用SELinux,然後在CentOS 8 Linux上永久禁用它。

如何在CentOS 8上暫時禁用SELinux

在開始在CentOS 8上禁用SELinux之前,請務必先檢查SELinux的狀态。

為此,請運作以下指令:

[root@localhost www.linuxidc.com]# sestatus

SELinux status:                enabled

SELinuxfs mount:                /sys/fs/selinux

SELinux root directory:        /etc/selinux

Loaded policy name:            targeted

Current mode:                  enforcing

Mode from config file:          enforcing

Policy MLS status:              enabled

Policy deny_unknown status:    allowed

Memory protection checking:    actual (secure)

Max kernel policy version:      31

這表明SELinux已啟動并正在運作。

要暫時禁用SELinux,請運作指令。

# setenforce 0

另外,您可以運作指令。

# setenforce Permissive

這些指令中的任何一個都将暫時禁用SELinux,直到下次重新開機為止。

如何在CentOS 8上永久禁用SELinux

現在,讓我們看看如何永久禁用SELinux。 SElinux的配置檔案位于 /etc/selinux/config。 是以,我們需要對該檔案進行一些修改。

# vi /etc/selinux/config

将SELinux屬性設定為Disabled,如下所示:

# 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.

SELINUX=disabled

# SELINUXTYPE= can take one of these three values:

#    targeted - Targeted processes are protected,

#    minimum - Modification of targeted policy. Only selected processes are protected.

#    mls - Multi Level Security protection.

SELINUXTYPE=targeted

儲存并退出配置檔案,然後使用以下任何指令重新啟動CentOS 8 Linux系統。

# reboot

# init 0

# telinit 0

現在,使用指令檢查SELinux的狀态。

[linuxidc@localhost www.linuxidc.com]$ sestatus

SELinux status:                disabled

SELinux是CentOS 8上非常關鍵的功能,有助于限制未經授權的使用者通路系統上的某些服務。

在本指南中,我們示範了如何在CentOS 8上禁用SELinux。理想情況下,除配置需要禁用SELinux的服務的執行個體外,始終建議保持SELinux處于啟用狀态。

希望您對本指南有所了解。 今天就這些。 非常歡迎您提供回報。