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
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...