成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

如何解決SELinux問題?

運維 系統運維
說起SELinux,多數Linux發行版缺省都激活了它,可見它對系統安全的重要性,可惜由于它本身有一定的復雜性,如果不熟悉的話往往會產生一些看似莫名其妙的問題,導致人們常常放棄使用它,為了不因噎廢食,學學如何解決SELinux問題是很有必要的。

說起SELinux,多數Linux發行版缺省都激活了它,可見它對系統安全的重要性,可惜由于它本身有一定的復雜性,如果不熟悉的話往往會產生一些看似莫名其妙的問題,導致人們常常放棄使用它,為了不因噎廢食,學學如何解決SELinux問題是很有必要的。

我們以CentOS環境為例重現一個非常常見的SELinux問題:

首先需要確認SELinux處于激活狀態,可以使用getenforce或sestatus命令:

  1. shell> getenforce  
  2. Enforcing  
  3.  
  4. shell> sestatus  
  5. SELinux status:                 enabled  
  6. SELinuxfs mount:                /selinux  
  7. Current mode:                   enforcing  
  8. Mode from config file:          enforcing  
  9. Policy version:                 24  
  10. Policy from config file:        targeted 

注:關于SELinux的基礎知識介紹請參考鳥哥的Linux私房菜中相關的介紹。

我們還需要確認系統已經安裝并啟動了Apache,沒有的話就YUM裝一個,這很簡單,就不多說了,接著在root目錄創建一個測試文件test.html,如下:

  1. shell> cat /root/test.html  
  2. hello, world. 

然后把這個測試文件拷貝到Apache的DocumentRoot目錄,我的Apache是通過YUM安裝的話,缺省是/var/www/html目錄,如下:

  1. shell> cp /root/test.html /var/www/html 

接著瀏覽一下,如果沒出什么幺蛾子,應該一切都在意料之中,如下:

  1. shell> curl http://localhost/test.html  
  2. hello, world. 

看到這,你可能覺得我廢話連篇,別著急,下面就是見證奇跡的時候了:

同樣還是那個測試文件test.html,不過這次不再是拷貝,而是移動,如下:

  1. shell> mv /root/test.html /var/www/html 

接著瀏覽一下,怎么樣,結果很出人意料吧,竟然提示權限錯誤,如下:

  1. shell> curl http://localhost/test.html  
  2. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
  3. <html><head> 
  4. <title>403 Forbidden</title> 
  5. </head><body> 
  6. <h1>Forbidden</h1> 
  7. <p>You don't have permission to access /test.html  
  8. on this server.</p> 
  9. </body></html> 

當然,我們現在知道這個問題是由于SELinux引起的,但還不知其所以然,實際上問題的原因此時已經被audit進程記錄到了相應的日志里,可以這樣查看:

  1. shell> audit2why < /var/log/audit/audit.log 

如果看不懂的話,推薦安裝setroubleshoot套件:

  1. shell> yum install setroubleshoot 

它本身是一個GUI套件,不過其中包含的一個sealert命令對我們命令行用戶很有用:

  1. shell> sealert -a /var/log/audit/audit.log  
  2. Summary:  
  3.  
  4. SELinux is preventing /usr/sbin/httpd "getattr" access to  
  5. /var/www/html/test.html.  
  6.  
  7. Detailed Description:  
  8.  
  9. SELinux denied access requested by httpd. /var/www/html/test.html may be a  
  10. mislabeled. /var/www/html/test.html default SELinux type is httpd_sys_content_t,  
  11. but its current type is admin_home_t. Changing this file back to the default  
  12. type, may fix your problem.  
  13.  
  14. File contexts can be assigned to a file in the following ways.  
  15.  
  16.   * Files created in a directory receive the file context of the parent  
  17.     directory by default.  
  18.   * The SELinux policy might override the default label inherited from the  
  19.     parent directory by specifying a process running in context A which creates  
  20.     a file in a directory labeled B will instead create the file with label C.  
  21.     An example of this would be the dhcp client running with the dhclient_t type  
  22.     and creating a file in the directory /etc. This file would normally receive  
  23.     the etc_t type due to parental inheritance but instead the file is labeled  
  24.     with the net_conf_t type because the SELinux policy specifies this.  
  25.   * Users can change the file context on a file using tools such as chcon, or  
  26.     restorecon.  
  27.  
  28. This file could have been mislabeled either by user error, or if an normally  
  29. confined application was run under the wrong domain.  
  30.  
  31. However, this might also indicate a bug in SELinux because the file should not  
  32. have been labeled with this type.  
  33.  
  34. If you believe this is a bug, please file a bug report against this package.  
  35.  
  36. Allowing Access:  
  37.  
  38. You can restore the default system context to this file by executing the  
  39. restorecon command. restorecon '/var/www/html/test.html', if this file is a  
  40. directory, you can recursively restore using restorecon -R  
  41. '/var/www/html/test.html'.  
  42.  
  43. Fix Command:  
  44.  
  45. /sbin/restorecon '/var/www/html/test.html' 

這次應該看懂了吧!原因是說Apache下文件上下文類型應該是httpd_sys_content_t,但是現在是admin_home_t,所以權限錯誤,并且在結尾處給出了修復命令。

可httpd_sys_content_t,admin_home_t都怎么看啊?很簡單,借助ls命令的-Z參數即可:

  1. shell> ls -Z /path 

回到問題的開始,拷貝之所以沒出現問題,是因為cp自動修改上下文屬性,而移動之所以出現問題是因為mv保留原文件的上下文屬性。

注:關于SELinux和Apache的詳細介紹,可以參考『man httpd_selinux』。

知道了如何解決SELinux問題,以后如果遇到類似的情況不要急著武斷的關閉SELinux。

責任編輯:黃丹 來源: huoding.com
相關推薦

2013-04-22 14:00:21

SELinux

2010-04-29 17:46:31

Oracle死鎖

2017-07-20 07:30:16

大數據數據互聯網

2024-10-29 16:41:24

SpringBoot跨域Java

2013-05-21 10:49:59

Windows硬件沖突

2011-08-29 10:34:00

網絡安全云安全云計算

2023-10-30 18:35:47

MySQL主從延時

2021-06-06 13:05:15

前端跨域CORS

2011-03-23 14:42:47

CPU過度消耗

2017-10-17 09:21:06

2010-07-16 13:52:26

telnet漏洞

2024-11-21 16:47:55

2009-09-21 17:10:14

struts Hibe

2011-09-05 13:32:56

2021-10-20 20:27:55

MySQL死鎖并發

2023-05-25 08:00:36

阿?云DNS重試機制

2025-02-11 12:29:58

2019-07-30 08:28:44

VirtualBox橋接網絡

2010-03-24 09:25:36

Nginx配置

2020-06-29 15:03:34

遠程工作網絡安全網絡攻擊
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 成人不卡 | 欧美操操操 | 欧洲毛片| 国产视频不卡一区 | av资源网站 | 91精品国产高清久久久久久久久 | 精品成人佐山爱一区二区 | 久久99精品久久久久久 | 天堂一区二区三区 | 精品久久久一区二区 | 国产色片在线 | 国产精品视频999 | 日日骚网 | 男人的天堂久久 | 亚洲欧美日韩中文在线 | 日日摸天天添天天添破 | 国产精品视频免费看 | 欧美一区二区三区在线视频 | 91精品国产一区二区三区 | 大陆一级毛片免费视频观看 | 欧美久久一区二区三区 | 国产成人精品久久二区二区91 | 91麻豆精品国产91久久久更新资源速度超快 | 天天操天天干天天爽 | 日本在线看片 | 91成人| 国产欧美精品 | 在线观看涩涩视频 | 国产精品视频久久久久久 | 男人天堂色 | av电影一区 | 亚洲精品视频二区 | www.一级毛片 | 成人高清网站 | 欧美国产亚洲一区二区 | 精品自拍视频 | 一级片免费视频 | 99re在线视频 | 亚洲黄色在线免费观看 | www.yw193.com | 亚洲成人av在线播放 |