apache 訪問許可權出錯,apache selinux 許可權問題, (13) Permission Denied

来源:https://www.cnblogs.com/xuyaowen/archive/2018/08/20/httpd_selinux.html
-Advertisement-
Play Games

今天在使用 httpd 做文件伺服器的時候,發現 png 圖像沒有打開,但是原本www/html 文件夾內部的文件就可以打開。後來猜測是selinux 的問題,之前一直想寫一篇關於selinux 的博文,現在先在這裡提到一點吧。 欲詳細解決 (13) Permission Denied 問題, 可以 ...


今天在使用 httpd 做文件伺服器的時候,發現 png 圖像沒有打開,但是原本www/html 文件夾內部的文件就可以打開。後來猜測是selinux 的問題,之前一直想寫一篇關於selinux 的博文,現在先在這裡提到一點吧。

欲詳細解決  (13) Permission Denied 問題, 可以參考apache 官方文檔 (13) Permission Denied

我們可以首先使用 setenforce 0 讓selinux 暫時關閉,定位到是否是selinux 許可權的問題。如果 關閉後,可以正常訪問,我們可以進一步來進行解決:

用過 ls -Z 查看 selinux 許可權:

root@yaowenxu /v/w/html# ls -alZ
total 176
drwxr-xrwx. 2 root     root     system_u:object_r:httpd_sys_content_t:s0      4096 Aug 20 13:24  ./
drwxr-xr-x. 4 root     root     system_u:object_r:httpd_sys_content_t:s0      4096 Jul 20 18:30  ../
-rw-r--r--. 1 xuyaowen xuyaowen unconfined_u:object_r:httpd_sys_content_t:s0 10292 Aug 19 17:51 'Screenshot from 2018-08-19 17-50-59.png'
-rw-r--r--. 1 xuyaowen xuyaowen unconfined_u:object_r:httpd_sys_content_t:s0 68579 Aug 20 11:32 'Screenshot from 2018-08-20 11-32-51.png'
-rw-r--r--. 1 xuyaowen xuyaowen unconfined_u:object_r:httpd_sys_content_t:s0 85378 Aug 20 13:24 'Screenshot from 2018-08-20 13-24-10.png'
-rw----r--. 1 root     root     unconfined_u:object_r:httpd_sys_content_t:s0     9 Aug 20 11:47  xuyaowen

查看是否是 httpd_sys_content_t 許可權,如果不是,通過命令進行設置許可權,我這裡讓http 所有文件設置為上述預設許可權:

root@yaowenxu /v/w/html# chmod -R -t httpd_sys_content_t html

這樣便能保持 selinux 的許可權的一致性。不用多次修改了。

當然你也可以禁止 selinux : 暫時禁止使用 setenforce 命令,永久禁止修改配置文件,如下所示:

vi /etc/sysconfig/selinux  
    SELINUX=enforcing --> SELINUX=disabled  

不保護apache:

setsebool -P httpd_disable_trans 1  

更多配置相關,請通過man命令,參考 selinux 說明和 selinux/apache 說明。

httpd_selinux(8)      httpd Selinux Policy documentation      httpd_selinux(8)

NAME
httpd_selinux - Security Enhanced Linux Policy for the httpd daemon

DESCRIPTION
Security-Enhanced Linux secures the httpd server via flexible mandatory
access control.

FILE_CONTEXTS
SELinux requires files to have an extended attribute to define the file
type.   Policy governs the access daemons have to these files.  SELinux
httpd policy is very flexible allowing users to setup  their  web  ser-
vices in as secure a method as possible.

The following file contexts types are defined for httpd:

httpd_sys_content_t
- Set files with httpd_sys_content_t for content which is avail-
able from all httpd scripts and the daemon.

httpd_sys_script_exec_t
- Set cgi scripts with httpd_sys_script_exec_t to allow them  to
run with access to all sys types.

httpd_sys_script_ro_t
-   Set   files   with   httpd_sys_script_ro_t   if   you   want
httpd_sys_script_exec_t scripts to read the data,  and  disallow
other sys scripts from access.

httpd_sys_script_rw_t
-   Set   files   with   httpd_sys_script_rw_t   if   you   want
httpd_sys_script_exec_t scripts to read/write the data, and dis-
allow other non sys scripts from access.

httpd_sys_script_ra_t
-   Set   files   with   httpd_sys_script_ra_t   if   you   want
httpd_sys_script_exec_t scripts to read/append to the file,  and
disallow other non sys scripts from access.

httpd_unconfined_script_exec_t
-  Set  cgi scripts with httpd_unconfined_script_exec_t to allow
them to run without any SELinux protection. This should only  be
used  for  a  very  complex  httpd scripts, after exhausting all
other options.  It is better to  use  this  script  rather  than
turning off SELinux protection for httpd.

NOTE
With  certain  policies  you can define addional file contexts based on
roles like user or  staff.   httpd_user_script_exec_t  can  be  defined
where it would only have access to "user" contexts.

SHARING FILES
If  you  want to share files with multiple domains (Apache, FTP, rsync,
Samba), you can set a file context of public_content_t and  public_con-
tent_rw_t.   These  context  allow any of the above domains to read the
content.  If you want a particular domain to write to  the  public_con-
tent_rw_t    domain,    you   must   set   the   appropriate   boolean.
allow_DOMAIN_anon_write.  So for httpd you would execute:

setsebool -P allow_httpd_anon_write=1

or

setsebool -P allow_httpd_sys_script_anon_write=1

BOOLEANS
SELinux policy is customizable based on least access required.   So  by
default SElinux prevents certain http scripts from working.  httpd pol-
icy is extremely flexible and has several booleans that  allow  you  to
manipulate  the policy and run httpd with the tightest access possible.

httpd  can  be  setup  to  allow  cgi  scripts  to  be  executed,   set
httpd_enable_cgi to allow this

setsebool -P httpd_enable_cgi 1

httpd by default is not allowed to access users home  directories.   If
you  want to allow access to users home directories you need to set the
httpd_enable_homedirs boolean and change the context of the files  that
you want people to access off the home dir.

setsebool -P httpd_enable_homedirs 1
chcon -R -t httpd_sys_content_t ~user/public_html

httpd by default is not allowed access to the controling terminal.   In
most  cases  this is prefered, because an intruder might be able to use
the access to the terminal to gain privileges. But  in  certain  situa-
tions  httpd needs to prompt for a password to open a certificate file,
in these cases, terminal access is required.   Set  the  httpd_tty_comm
boolean to allow terminal access.

setsebool -P httpd_tty_comm 1

httpd can be configured to not differentiate  file  controls  based  on
context, i.e. all files labeled as httpd context can be read/write/exe-
cute.  Setting this boolean to false allows you to setup  the  security
policy such that one httpd service can not interfere with another.

setsebool -P httpd_unified 0

httpd can be configured to turn off internal scripting (PHP).  PHP  and
other
loadable modules run under the same context as httpd.  Therefore
several  policy  rules  allow httpd greater access to the system
then is needed if you only use external cgi scripts.

setsebool -P httpd_builtin_scripting 0

httpd scripts by default are not allowed to connect out to the network.
This would prevent a hacker from breaking into you httpd  server
and attacking other machines.  If you need scripts to be able to
connect you can set the httpd_can_network_connect boolean on.

setsebool -P httpd_can_network_connect 1

You can disable suexec transition, set httpd_suexec_disable_trans  deny
this

setsebool -P httpd_suexec_disable_trans 1

You can disable SELinux protection for the httpd daemon by executing:

setsebool -P httpd_disable_trans 1
service httpd restart

system-config-securitylevel  is  a  GUI  tool  available  to  customize
SELinux policy settings.

AUTHOR
This manual page was written by Dan Walsh <[email protected]>.

SEE ALSO
selinux(8), httpd(8), chcon(1), setsebool(8)

[email protected]                 17 Jan 2005                 httpd_selinux(8)
View Code

 保持更新,轉載請註明出處。如果對你有幫助,請點擊右下角推薦。

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 一、進程與線程 進程是處於執行期的程式,但是並不僅僅局限於一段可執行程式代碼。通常,進程還要包含其他資源,像打開的文件,掛起的信號,內核內部數據,處理器狀態,一個或多個具有記憶體映射的記憶體地址空間及一個或多個執行線程,當然還包括用來存放全局變數的數據段等。在Linux內核中,進程也通常叫做任務。 執行 ...
  • 實例整體框架: 使用VMware搭建 5台Centos7虛擬機(包括客戶端),系統版本:CentOS Linux release 7.2.1511。實例所安裝的nginx版本:1.12.2,mariadb-server版本:5.5.56,php-fpm版本:5.4.16,PHPMyAdmin版本:4 ...
  • 幫助搭建快速建立ftp,實現多用戶管理的功能,並且可以對每一個用戶進行操作限制 ...
  • 1、隱藏Nginx版本號信息 編輯nginx.conf配置文件在http標簽增加”server_tokens off;“參數,實現隱藏Nginx版本號的方式如下: ##在http {}內添加 http { server_tokens off; } curl命令進行查看Nginx版本號; 通過-I或者 ...
  • 1. ls 查看當前目錄下的所有文件夾 2. pwd 查看當前所在的文件夾 3. cd 目錄名 切換文件夾 4. touch 文件名 創建文件 5. mkdir 目錄名 創建文件夾 6. rm 文件名 刪除文件 7. clear 清屏(實際上是將當前行設定為 第一行,並不是通常意義上的清楚 內容,類 ...
  • 將PDF轉換成HTML,是打造專業網站最快速便捷的方法之一,不過,當小伙伴們找來一堆詳細的PDF資料,想將它轉換為網頁格式,重新手動開發會消耗大量的時間和精力,非常的麻煩。此時如果有一種快速、批量將PDF轉換為HTML的方法,工作效率就會大大提升。 所以,今天小編就給大伙兒介紹一種快速將PDF轉換成 ...
  • 今天,在使用fedora時,需要修改防火牆規則,一時間忘記了命令是什麼,這裡進行記錄一下。 目前 fedora 28/ centos 7 使用 firewalld 作為防火牆軟體;下麵我就怎麼簡單管理防火牆規則進行記錄,網上的例子很多,這裡我列舉我經常使用的命令,來進行備忘: 基本使用(使用這些命令 ...
  • 一個網站項目,肯定是避免不了404頁面的,通常使用Nginx作為Web伺服器時,有以下集中配置方式,一起來看看。 第一種:Nginx自己的錯誤頁面 Nginx訪問一個靜態的html 頁面,當這個頁面沒有的時候,Nginx拋出404,那麼如何返回給客戶端404呢? 看下麵的配置,這種情況下不需要修改任 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...