Linux中的SELinux详解--16
SELinux?寬容模式(permissive)?強制模式(enforcing)?關閉(disabled)??幾種模式之間的轉換
在CentOS6.2 中安裝intel 的c++和fortran 的編譯器時,遇到來一個關于SELinux的強制模式不可執行的情況,需要關閉SELinux 或者 將enforcing改為 permissive 模式,查詢來一些資料后,先對SELinux的幾種模式,以及其之間的關系和轉換方法做一小結,以備以后查看和學習。
SELinux 的啟動、關閉與查看?
1、并非所有的 Linux distributions 都支持 SELinux?
目前 SELinux 支持三種模式,分別如下:?
?enforcing:強制模式,代表 SELinux 運作中,且已經正確的開始限制 domain/type 了; ?permissive:寬容模式:代表 SELinux 運作中,不過僅會有警告訊息并不會實際限制 domain/type 的存取。這種模式可以運來作為 SELinux 的 debug 之用;
?disabled:關閉,SELinux 并沒有實際運作。
2,查看SELinux的模式
# getenforce Enforcing <==就顯示出目前的模式為 Enforcing
3,查看 SELinux 的政策 (Policy)?
[root@master oracle]# sestatus
SELinux status: enabled <==是否啟動 SELinux
SELinuxfs mount: /selinux <==SELinux 的相關文件資料掛載點
Current mode: enforcing <==目前的模式
Mode from config file: enforcing <==設定檔指定的模式
Policy version: 21
Policy from config file: targeted <==目前的政策為何? 4,通過配置文件調整SELinux的參數? [root@www ~]# vi /etc/selinux/config?
SELINUX=enforcing <==調整 enforcing|disabled|permissive?
SELINUXTYPE=targeted <==目前僅有 targeted 與 strict?
5,SELinux 的啟動與關閉?
【重要常識】上面是預設的政策與啟動的模式!你要注意的是,如果改變了政策則需要重新開機;如果由 enforcing 或 permissive 改成 disabled ,或由 disabled 改成其他兩個,那也必須要重新開機。這是因為 SELinux 是整合到核心里面去的, 你只可以在 SELinux 運作下切換成為強制 (enforcing) 或寬容 (permissive) 模式,不能夠直接關閉 SELinux 的!?
同時,由 SELinux 關閉 (disable) 的狀態到開啟的狀態也需要重新開機啦!所以,如果剛剛你發現 getenforce 出現 disabled 時, 請到上述文件修改成為 enforcing 吧!
【重點】如果要啟動SELinux必須滿足以下兩個點:?
所以,如果你要啟動 SELinux 的話,請將上述的 SELINUX=enforcing 設定妥當,并且指定 SELINUXTYPE=targeted 這一個設定, 并且到 /boot/grub/menu.lst 這個文件去,看看核心有無關閉 SELinux 了呢?
[root@www ~]# vi /boot/grub/menu.lst?
default=0?
timeout=5?
splashimage=(hd0,0)/grub/splash.xpm.gz?
hiddenmenu?
title CentOS (2.6.18-92.el5)?
??????root (hd0,0)?
??????kernel /vmlinuz-2.6.18-92.el5 ro root=LABEL=/1 rhgb quiet selinux=0?
??????initrd /initrd-2.6.18-92.el5.img?
# 如果要啟動 SELinux ,則不可以出現 selinux=0 的字樣在 kernel 后面!?
【問題】通過上面的學習我們知道,如果將啟動著的SELinux改為禁用,需要重啟電腦,我們不想重啟電腦又不想開啟SELinux該怎么辦呢??
【答案】將強制模式改為寬松模!?
[root@www ~]# setenforce [0|1]?
選項與參數:?
0 :轉成 permissive 寬容模式;?
1 :轉成 Enforcing 強制模式
范例一:將 SELinux 在 Enforcing 與 permissive 之間切換與查看?
[root@www ~]# setenforce 0?
[root@www ~]# getenforce Permissive?
[root@www ~]# setenforce 1?
[root@www ~]# getenforce Enforcing
6,查看已啟動程序的type設定?
[root@master oracle]# ps aux -Z?
LABEL USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND?
system_u:system_r:init_t root 1 0.0 0.4 2060 520 ? Ss May07 0:02 init [5 system_u:system_r:kernel_t root 2 0.0 0.0 0 0 ? S< May07 0:00 [migra] system_u:system_r:kernel_t root 11 0.0 0.0 0 0 ? S< May07 0:00 [kacpi] system_u:system_r:auditd_t root 4022 0.0 0.4 12128 560 ? S<sl May07 0:01 auditd system_u:system_r:auditd_t root 4024 0.0 0.4 13072 628 ? S<sl May07 0:00 /sbin/a system_u:system_r:restorecond_t root 4040 0.0 4.4 10284 5556 ? Ss May07 0:00 /usr/sb?
說明:其實這些東西我們都不用管,都是SELinux內置的。只要學會在強制和寬松模式間轉換就行了!
小結附:
關閉SELinux的方法:
修改/etc/selinux/config文件中的SELINUX="" 為 disabled ,然后重啟。
如果不想重啟系統,使用命令setenforce 0
注:
setenforce 1 設置SELinux 成為enforcing模式
setenforce 0 設置SELinux 成為permissive模式
在lilo或者grub的啟動參數中增加:selinux=0,也可以關閉selinux
#---------------------------------------------------------------
查看selinux狀態:
/usr/bin/setstatus -v
如下:
SELinux status:?????????????????enabled
SELinuxfs mount:????????????????/selinux
Current mode:???????????????????permissive
Mode from config file:??????????enforcing
Policy version:?????????????????21
Policy from config file:????????targeted
?
getenforce/setenforce查看和設置SELinux的當前工作模式
#-----------------------------------------------------------------------
???發現服務一啟動,馬上停止,在網上查找資料,找到安裝時要先禁用SELinux,再安裝MySQL,步驟是:
1. 關閉SELinux,重啟系統;
2. 安裝MySQL(MySQL server應該可以啟動了);
3. 啟用SELinux,重啟系統,之后MySQL server就可以正常啟動了。
???啟用禁用SELinux的方法是:
???vi /etc/selinux/config(也有人說是/etc/sysconfig/selinux文件,其實兩個之間是鏈接關系,隨便改其中一個,另一個也改了)
???SELINUX=disable 禁用SeLinux
???SELINUX=enforcing 啟用SeLinux
CentOS系統如何快速關閉SELINUX
SELinux是一種基于 域-類型 模型(domain-type)的強制訪問控制(MAC)安全系統,它由NSA編寫并設計成內核模塊包含到內核中,相應的某些安全相關的應用也被打了 SELinux的補丁,最后還有一個相應的安全策略。雖然CentOS系統相比較而言相對安全穩定。我在長期的linux實踐中總結的經驗 是:SElinux是php的天敵。
我們經常由于CentOS系統默認系統的安全性配置導致些莫名其妙的問題,比如SElinux本來是用于安全子系統的權限控制,可是搞不好就發現限制多多,我們可以用如下方法快速關閉SElinux。
/usr/sbin/setenforce 0 立刻關閉SELINUX
/usr/sbin/setenforce 1 立刻啟用 SELINUX
加到系統默認啟動里面
echo "/usr/sbin/setenforce 0" >> /etc/rc.local
這樣,我們在不需要在CentOS系統中開啟SELINUX的時候,就可以快速的去關閉了,以及在需要的時候,在開啟它。
轉載于:https://www.cnblogs.com/zxouxuewei/p/5002475.html
總結
以上是生活随笔為你收集整理的Linux中的SELinux详解--16的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 那个好好玩的特效,每个人都可以做到哦
- 下一篇: linux 其他常用命令