成人免费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死鎖

2011-08-29 10:34:00

網絡安全云安全云計算

2021-06-06 13:05:15

前端跨域CORS

2011-03-23 14:42:47

CPU過度消耗

2010-07-16 13:52:26

telnet漏洞

2023-10-30 18:35:47

MySQL主從延時

2017-10-17 09:21:06

2017-07-20 07:30:16

大數據數據互聯網

2024-10-29 16:41:24

SpringBoot跨域Java

2013-05-21 10:49:59

Windows硬件沖突

2024-11-21 16:47:55

2010-03-24 09:25:36

Nginx配置

2020-06-29 15:03:34

遠程工作網絡安全網絡攻擊

2019-11-26 14:30:20

Spring循環依賴Java

2020-04-24 16:01:26

物聯網數據IOT

2017-08-02 15:51:24

PHP中文亂碼

2024-02-21 14:35:38

區塊鏈智慧城市數字化身份證

2009-06-30 15:22:55

JSP頁面

2023-03-27 11:33:37

人工智能物聯網
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 精品日韩在线 | 一区二区三区影院 | 色综合色综合色综合 | 男人天堂视频在线观看 | 国内精品视频 | 日韩一区二区三区在线 | 日韩伦理电影免费在线观看 | 欧美不卡一区二区三区 | 成人在线视频一区二区三区 | 羞羞视频在线免费 | 色悠悠久 | 国产精品178页 | 日韩欧美在线视频观看 | 亚洲精品久久嫩草网站秘色 | h视频在线播放 | 综合国产| 国产99视频精品免费播放照片 | 91视频在线观看免费 | 草草视频在线观看 | 国产精品自在线 | 日本人麻豆 | 在线久草| 久久99精品久久久久久 | 日日操日日干 | 热久久免费视频 | 中文字幕亚洲一区 | 精品欧美一区二区三区精品久久 | 国产精品一区二区久久 | 国产成人福利在线观看 | 久草视频观看 | 国产欧美日韩一区 | 亚洲欧美中文日韩在线v日本 | 男人天堂视频在线观看 | 国产欧美日韩视频 | 岛国av免费在线观看 | 亚洲电影第三页 | 99亚洲视频 | 亚洲综合一区二区三区 | 男女视频免费 | 欧美激情久久久 | 青春草在线 |