Linux伺服器關閉SeLinux的方法

來源:互聯網
上載者:User

標籤:io   ar   os   使用   sp   for   檔案   on   art   

[[email protected] ~]$ cat /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=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

 

關閉SELinux的方法:
  修改/etc/selinux/config檔案中的SELINUX="" 為 disabled ,然後重啟。
  如果不想重啟系統,使用命令setenforce 0
註:
setenforce 1 設定SELinux 成為enforcing模式
setenforce 0 設定SELinux 成為permissive模式

2,查看SELinux的模式
# getenforce
Enforcing  <==就顯示出目前的模式為 Enforcing
 
3,查看 SELinux 的政策
# 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  

 

【重點】如果要啟動SELinux必須滿足以下兩個點:
所以,如果你要啟動 SELinux 的話,請將上述的 SELINUX=enforcing 設定妥當,並且指定 SELINUXTYPE=targeted 這一個設定, 並且到 /boot/grub/menu.lst 這個檔案去,看看核心有無關閉 SELinux 了呢?
[[email protected] ~]# 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該怎麼辦呢?
【答案】將強制模式改為寬鬆模!
[[email protected] ~]# setenforce [0|1]
選項與參數:
0 :轉成 permissive 寬容模式;
1 :轉成 Enforcing 強制模式
 
範例一:將 SELinux 在 Enforcing 與 permissive 之間切換與查看
[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce
Permissive
[[email protected] ~]# setenforce 1
[[email protected] ~]# getenforce
Enforcing
 
6,查看已啟動程式的type設定
[[email protected] 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內建的。只要學會在強制和寬鬆模式間轉換就行了!

 

Linux伺服器關閉SeLinux的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.