Selinux:SELinux(Security-EnhancedLinux) 是美國國家安全局(NSA)對于強制通路控制的實作,是 Linux曆史上最傑出的新本機安全性授權。
雖然是一個安全功能,可是由于功能太多了,什麼都要管,是以用起來反而更麻煩,因而可以把它關閉,進而使用其它的安全方式替代。
【1】檢視Selinux運作的3種模式
1
2
3
4
5
6
7
8
9
10
11
<code>[root@moban ~]#cat /etc/selinux/config #此為Selinux的配置檔案目錄</code>
<code># This filecontrols the state of SELinux on the system.</code>
<code># SELINUX= cantake one of these three values:</code>
<code># enforcing - SELinux security policy isenforced.</code>
<code># permissive - SELinux prints warningsinstead of enforcing.</code>
<code># disabled - No SELinux policy </code><code>is</code> <code>loaded.</code>
<code>SELINUX=enforcing</code>
<code># SELINUXTYPE=can take one of these two values:</code>
<code># targeted - Targeted processes areprotected,</code>
<code># mls - Multi Level Security protection.</code>
<code>SELINUXTYPE=targeted</code>
可以看到有3種運作模式:
<code>enforcing:開啟Selinux</code>
<code>permissive:自由模式,此種模式下,隻會列印警告消息,但不會阻止</code>
<code>disabled:關閉Selinux</code>
【2】更改Selinux配置檔案的運作模式
方法一:使用vi檔案編輯器修改
<code>[root@moban ~]# vi /etc/selinux/config</code>
将“SELINUX=enforcing”修改為“SELINUX=disabled”,儲存退出即可
方法二:sed指令
<code>[root@moban ~]#sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/selinux/conf</code>
<code>[root@moban ~]#grep </code><code>"disabled"</code> <code>/etc/selinux/config</code>
<code>SELINUX=disabled</code>
注意一定要加參數-i,否則隻改變輸出,而不是改變配置檔案的内容。但是需要注意的是,由于修改Selinux的配置檔案需要在下一次重新開機後才生效,是以目前Selinux實際運作狀态仍是enforcing,是以需要再進行一些設定。(為了不重新開機Linux系統)
【3】更改Selinux的目前運作模式
檢視目前運作模式:
<code>[root@moban ~]#getenforce </code>
<code>Enforcing</code>
将目前模式修改為permissive狀态:
<code>[root@moban ~]# setenforce </code><code>0</code>
<code>Permissive</code>
注意到此時已經将目前Selinux的運作模式改變為permissive狀态,如果仍需改回enforcing狀态則輸入setenforce 1即可,但注意setenforce隻有參數0和1:
<code>[root@moban ~]#setenforce </code><code>1</code>
<code>[root@moban ~]# setenforce2</code>
<code>usage: setenforce [ Enforcing | Permissive | </code><code>1</code> <code>| </code><code>0</code> <code>]</code>
改為permissive狀态後,雖然會列印警告消息,但對實際操作是沒有影響的,是以可以達到目的。
由此可知,以上兩種修改方式,第一種為永久修改,第二種為臨時修改。
本文轉自 xpleaf 51CTO部落格,原文連結:http://blog.51cto.com/xpleaf/1657735,如需轉載請自行聯系原作者