SELinux(Secrity-Enhanced Linux,安全增強式Linux)是一種強制存取控制的實現,它的作法是以最小權限原則為基礎提供一些更強、更安全的強制存取控制架構來與內核的主要子系統共同動作。
SELinux等級有三個:
Enforcing: 強制的,如果違反則直接阻止
Permissive: 在違反規則時只警告,但是不阻止
Disables:表示 SELinux不啟用
在啟動SELinux時要重新啟動系統才能使用。
SELinux可以通過不同的方式進行啟動與關閉,也可以使它暫時的關閉與開啟
永久關閉方法:1>setupàFirewall configuration-SELinux 自己選擇打開關閉
2>使用命令:[root@localhost ~]# system-config-securitylevel 也可以選擇
暫時關閉方法:setenforce 1 :暫時關閉SELinux
setenforce 0 :開啟SELinux Permissive
簡單查看SELinux的狀態:
getenforce
SELinux中訪問控制屬性就叫安全上下文,所有的客體(如文件,進程間通信)和主體(進程)都有與其並聯的安全上下文,一個安全上下文由用戶、角色、和類型標識符3個部分組成,如下命令可以看到文件的安全上下文屬性
在SELlinux中安全上下文中的用戶和角色標識符除了對強制有一點約束之外對類型強制訪問控制策略沒有任何影響。我們看一個小例子來說明一下類型標識符的限制。
示例1 http的SELinux應用
[root@localhost www]# cd /mnt/cdrom/Server/
[root@localhost Server]# rpm -ivh httpd-2.2.3-31.el5.i386.rpm
warning: httpd-2.2.3-31.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ################################### [100%]
1:httpd ################################### [100%]
現在我們可以正常的啟動http服務
[root@localhost ~]# service httpd start
Starting httpd: [ OK ]
但是我們如果修改一下http默認的主目錄,會出現怎麼樣的情況呢!
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
將<Directory "/var/www/html"> 修改為 <Directory "/html">
創建目錄
[root@localhost ~]# mkdir /html
這時候我們再來重新啟動一次
[root@localhost ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Syntax error on line 306 of /etc/httpd/conf/httpd.conf: /etc/httpd/conf/httpd.conf:306: <Directory> was not closed.
[FAILED]