• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 297,  comments - 15,  trackbacks - 0

            看了很多網(wǎng)路上有關(guān)於 SELinux 的文章以及到書店去翻了一下有提到 SELinux 的 Linux 書籍
            看完了的感覺不是很好
            幾乎都沒提到什麼是 SELinuxSELinux 的運作機(jī)制是什麼?
            大部份提到的解決辦法,都是 “請把 SELinux 停用”
            這樣也只不過是治標(biāo)而不是治本的方法

            SELinux 的設(shè)定檔

            * /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 - SELinux is fully disabled.
            SELINUX=enforcing
            # SELINUXTYPE= type of policy in use. Possible values are:
            # targeted - Only targeted network daemons are protected.
            # strict - Full SELinux protection.
            SELINUXTYPE=targeted

            若要停用 SELinux, 則把 SELINUX=enforcing 改成 SELINUX=disabled 後重新開機(jī)即可

            SELinux 的一些相關(guān)指令

            * sestatus
            查看 SELinux 是否啟用及目前狀態(tài)如何的指令
            如:
            1.SELinux Disabled

            $ sestatus
            SELinux status: disabled

            2.SELinux Enabled
            mode: enforcing
            Policy: targeted

            $ sestatus
            SELinux status: disabled
            SELinux status: enabled
            SELinuxfs mount: /selinux
            Current mode: enforcing
            Mode from config file: enforcing
            Policy version: 18
            Policy from config file:targeted

            Policy booleans:
            ...skip...
            httpd_builtin_scripting active
            httpd_disable_trans active
            httpd_enable_cgi active
            httpd_enable_homedirs active
            httpd_ssi_exec active
            httpd_tty_comm inactive
            httpd_unified active
            ...skip...

            * system-config-securitylevel
            圖形化介面的工具程式,除了可以設(shè)定防火牆(iptables)外,也可以設(shè)定 SELinux

            * setenforce
            SELinux 啟動為 enforcing 的狀況下,可以執(zhí)行 “setenforce 0“ 來將 SELinux 暫時停用

            * getsebool and setsebool
            /etc/selinux/targeted/booleans 這個檔裡面放的就是各個 Policy 的布林值,不過,在 FC5 之後,已經(jīng)沒有這個檔了,你可以用
            $ getsebool -a
            來查看所有的 booleans 設(shè)定狀況
            或是使用如:
            $ setsebool -P httpd_disable_trans 1
            來將 httpd_disable_trans 停用,這樣其實也就等於是停用 SELinuxhttpd 的保護(hù)了

            * chcon
            傳統(tǒng)的 chmod 指令是用來設(shè)定檔案或目錄的權(quán)限的,而同樣的 chcon 指令則是用來設(shè)定 SELinux 對檔案或目錄的 content 標(biāo)籤的

            * fixfiles
            fixfiles check 指令可以用來檢查檔案或目錄的 SELinux content
            fixfiles restore 指令則可以用來修正(還原)檔案或目錄的 SELinux content
            fixfiles relabel 則是會重新修正(還原)所有的檔案及目錄的 SELinux content

            如何在 SELinux 啟動為 enforcing 的狀況下也讓 Web Server(httpd) 能正常運作?

            前面提到,我們可以將 SELinux 停用(disabled) 或是執(zhí)行 “setsebool -P httpd_disable_trans 1“ 來停用 SELinuxhttpd 的保護(hù),這樣,httpd 就可以跟平常一樣的運作了
            那如果我們要啟用 SELinux 且讓 httpd 也可以正常運作呢?
            舉個例子來說:

            [root@acer:~] pwd
            /root
            [root@acer:~] echo "" > index.php
            [root@acer:~] mv index.php /var/www/html/
            `index.php' -> `/var/www/html/index.php'
            [root@acer:~]

            在上述的指令中,我在 root 的 $HOME 目錄下產(chǎn)生了一個 index.php 的檔案,內(nèi)容為顯示 phpinfo
            然後把再把這個檔案搬移到 /var/www/html 目錄底下,然後開 browser 來瀏覽 http://localhost/index.php 這個頁面,得到的畫面卻是:

            Forbidden

            You don't have permission to access /index.php on this server.

            Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

            沒錯,無法存取,我們來看一看到底是怎麼回事:

            [root@acer:~] ls -Z /var/www/html/index.php
            -rw-r--r-- root root root:object_r:user_home_t /var/www/html/index.php
            [root@acer:~]
            [root@acer:~] ls -Z /var/www/
            drwxr-xr-x root root system_u:object_r:httpd_sys_script_exec_t cgi-bin/
            drwxr-xr-x root root system_u:object_r:httpd_sys_content_t error/
            drwxr-xr-x root root system_u:object_r:httpd_sys_content_t html/
            drwxr-xr-x root root system_u:object_r:httpd_sys_content_t icons/
            drwxr-xr-x root root system_u:object_r:httpd_sys_content_t manual/

            因為 index.php 的 content type 為 user_home_t 而不是 httpd_sys_content_t 所以無法存取
            因此,我們可以執(zhí)行:

            [root@acer:~] chcon -u system_u -t httpd_sys_content_t /var/www/html/index.php
            [root@acer:~] ls -Z /var/www/html/index.php
            -rw-r--r-- root root system_u:object_r:httpd_sys_content_t /var/www/html/index.php

            請再開一次 browser (or reload),現(xiàn)在是不是可以正常存取 index.php 頁面了呢?

            再看另一個例子:

            [root@acer:~] wget http://wordpress.org/latest.tar.gz
            --13:36:59-- http://wordpress.org/latest.tar.gz
            => `latest.tar.gz'
            Resolving wordpress.org... 72.232.44.122
            Connecting to wordpress.org|72.232.44.122|:80... connected.
            HTTP request sent, awaiting response... 200 OK
            Length: unspecified [application/octet-stream]

            [ ] 505,475 90.49K/s

            13:37:07 (90.28 KB/s) - `latest.tar.gz' saved [505475]

            [root@acer:~] tar zxf latest.tar.gz
            [root@acer:~] mv wordpress /var/www/html/wp
            `wordpress' -> `/var/www/html/wp'

            瀏覽 http://localhost/wp/ 的結(jié)果一樣被拒絕存取,因為 content 的問題

            [root@acer:~] ls -dZ /var/www/html/wp
            drwxr-xr-x 1025 1011 root:object_r:user_home_t /var/www/html/wp/

            同樣的,我們可以用 chone -R 指令來修正 content

            [root@acer:~] chcon -R -u system_u -t httpd_sys_content_t /var/www/html/wp/

            或是使用 fixfiles restore 指令也可以

            [root@acer:~] fixfiles restore /var/www/html/wp/

            修正過後的狀況:

            [root@acer:~] ls -dZ /var/www/html/wp
            drwxr-xr-x apache apache system_u:object_r:httpd_sys_content_t /var/www/html/wp/

            相關(guān)參考文件

            http://linux.vbird.org/somepaper/20050801_SELinux.pdf
            http://fedoraproject.org/wiki/SELinux
            http://fedora.redhat.com/docs/selinux-faq/
            http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/selinux-guide/
            http://www.redhat.com/magazine/001nov04/features/selinux/
            http://www.redhat.com/magazine/006apr05/features/selinux/
            http://www.tresys.com/selinux/index.shtml
            http://www.nsa.gov/selinux/


            from:

            http://blog.chinaunix.net/u1/38576/showart_1926391.html

            posted on 2010-04-01 17:22 chatler 閱讀(282) 評論(0)  編輯 收藏 引用 所屬分類: Linux_SysAdmin
            <2010年2月>
            31123456
            78910111213
            14151617181920
            21222324252627
            28123456
            78910111213

            常用鏈接

            留言簿(10)

            隨筆分類(307)

            隨筆檔案(297)

            algorithm

            Books_Free_Online

            C++

            database

            Linux

            Linux shell

            linux socket

            misce

            • cloudward
            • 感覺這個博客還是不錯,雖然做的東西和我不大相關(guān),覺得看看還是有好處的

            network

            OSS

            • Google Android
            • Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
            • os161 file list

            overall

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            精品免费tv久久久久久久| 久久精品国产2020| 久久久91精品国产一区二区三区| 久久丫精品国产亚洲av| 久久国产精品久久国产精品| 久久99热这里只有精品国产| 少妇久久久久久被弄到高潮 | 久久久久亚洲精品无码网址| 一本一道久久a久久精品综合| 国产Av激情久久无码天堂| 久久久久无码中| 国产午夜福利精品久久2021| 欧美日韩成人精品久久久免费看| 久久人人爽人人爽人人AV| 欧洲国产伦久久久久久久| 亚洲一本综合久久| 久久精品人成免费| 亚洲av日韩精品久久久久久a| 久久www免费人成精品香蕉| 国产精品青草久久久久婷婷| 亚洲精品无码久久久影院相关影片 | 久久久久久一区国产精品| 国产精品视频久久久| 亚洲精品无码久久久久| 最新久久免费视频| 久久影院久久香蕉国产线看观看| 国产一久久香蕉国产线看观看| 亚洲国产另类久久久精品小说| 国产精品久久久久久久人人看| 久久97久久97精品免视看| 亚洲国产精品一区二区久久| 久久丫精品国产亚洲av不卡 | 国内精品久久久久久久coent| 国产午夜福利精品久久2021| 亚洲va久久久噜噜噜久久男同 | 久久久精品午夜免费不卡| 久久亚洲精品国产精品| 精品国产一区二区三区久久久狼 | 精品久久8x国产免费观看| 精品永久久福利一区二区| 久久99精品久久久久久久不卡|