1. 程式人生 > >Linux優化之關閉SELinux

Linux優化之關閉SELinux

spa bug png 功能 can 分享 control size state

selinux簡介

SELinux(Security-Enhanced Linux) 是美國國家安全局(NSA)對於強制訪問控制的實現,是 Linux歷史上最傑出的新安全子系統。因為要對強制訪問進行控制,所以這個功能讓系統管理員又愛又恨,一大多數生產環境都是把他關閉,安全問題會通過其他手段來實現。

SELinux配置文件路徑在 /etc/selinux/config。其文件內容如下:

# 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 two values:

# targeted - Targeted processes are protected,

# mls - Multi Level Security protection.

SELINUXTYPE=targeted

SELINUX有「disabled」「permissive」,「enforcing」3種選擇。

permissive就是Selinux有效,但是即使你違反了策略的話它讓你繼續操作,但是把你的違反的內容記錄下來。在我們開發策略的時候非常的有用。相當於Debug模式。

Enforcing就是你違反了策略,你就無法繼續操作下去。

查看SELinux狀態:

1、/usr/sbin/sestatus -v ##如果SELinux status參數為enabled即為開啟狀態,若為disabled則為關閉狀態。

技術分享圖片

2、getenforce ##也可以用這個命令檢查

技術分享圖片

關閉SELinux:

1、臨時關閉(不用重啟機器):

setenforce命令:

##setenforce 0 設置SELinux 成為permissive模式

##setenforce 1 設置SELinux 成為enforcing模式

2、修改配置文件(需要重啟機器才能生效):

修改/etc/selinux/config 文件

將SELINUX=enforcing改為SELINUX=disabled(使用sed命令修改)

技術分享圖片

最後重啟機器即可

Linux優化之關閉SELinux