Linux 中httpd基於檔案的使用者的存取控制和CGI

來源:互聯網
上載者:User

標籤:linux   使用者   認證   資源   

基於使用者存取控制(這裡控制的是整個頁面控制)
        使用者認證類型:
            基本認證:Basic
            摘要認證:digest,是否明文還是密文的控制。

 
    虛擬使用者:僅用於訪問某服務和擷取資源的憑證:
        使用者帳號密碼存放位置:.htpasswd 這個檔案使用者名稱是明文的,密碼是加密的。這個檔案的名字也是你自己取的,一般我們不改動.htpasswd存放在httpd設定檔下即可 
              
執行個體:我們這裡基於檔案的認證(檔案存放賬戶的賬戶和密碼的認證)
        (1)編輯設定檔為需要認證的目錄做使用者認證
            </Directory "/var/www/ning/liang">-----指定要做認證的目錄
            Options none------不指定任何選項
            AllowOverride AuthConfig-----允許覆蓋,認證通常啟用為AuthConfig,說明做認證相關的配置
            AuthType Basic-----------指定認證類型
            AuthName "admin area."-----對使用者做說明的資訊,就是輸入密碼讓使用者知道為什麼做認證。
            AuthBasicProvider file------指定認證機制是什麼,預設為file(可以省略)
            AuthUserfile /etc/httpd/conf/.htpasswd ------指定存放認證的使用者和密碼的檔案。(需要我們自己建立)
            Require valid-user-----------valid-uer合格所有使用者可以登入,
            </Directory>
            單獨使用者指定格式如:Require user ning hong----兩使用者之間用空格隔開


        (2)建立認證檔案.htpasswd(這裡的賬戶是明文的,密碼是加密的,一般我們不手動編輯,用工具產生)
             產生認證檔案的工具:   
                htpasswd
                        -c:如果此檔案事先不存在,則建立;注意:只能是在建立第一個使用者時使用;
                        -m:以md5的格式編碼儲存使用者的密碼資訊
                        -D:刪除指定使用者 
             #htpasswd -c -m /etc/httpd/conf/.htpasswd tom-----沒有.htpasswd檔案第一次建立用-c,-m加密,指定路徑,後輸入使用者名稱
                    New password: -----輸入使用者的密碼
                    Re-type new password:
                    Adding password for user tom 
              #htpasswd -m /etc/httpd/conf/.htpasswd qing-------這裡就不需要建立.htpasswd,直接添加即可。 
              #cat /etc/httpd/conf/.htpasswd
                    tom:$apr1$o3HNsazw$rxcLVyixdNTnzOrGji3qD.------這裡密碼是用md5加密的。
                    qing:$apr1$TLIArC5B$PFnEPKdDEMCXLRBbnnNIm. 
            # htpasswd -D /etc/httpd/conf/.htpasswd qing-----刪除使用者qing
                    Deleting password for user qing 
               # cat /etc/httpd/conf/.htpasswd ----------查看下刪除的結果
                    tom:$apr1$o3HNsazw$rxcLVyixdNTnzOrGji3qD.

   
            (3)組檔案認證
                </Directory "/var/www/ning/liang">-----指定要做認證的目錄
                Options none------不指定任何選項
                AllowOverride AuthConfig-----允許覆蓋,認證通常啟用為AuthConfig,說明做認證相關的配置
                AuthType Basic-----------指定認證類型
                AuthName "admin area."-----對使用者做說明的資訊,就是輸入密碼讓使用者知道為什麼做認證。
                AuthBasicProvider file------指定認證機制是什麼,預設為file(可以省略)
                AuthUserfile /etc/httpd/conf/.htpasswd ------指定存放認證的使用者和密碼的檔案。(需要我們自己建立)
                AuthGroupfile /etc/httpd/conf/.htgroup-------指定使用者組檔案(需要我們自己建立)
                Require group test-----------指定組名
                </Directory>

建立編輯組檔案 
          組檔案格式: 組名:user1 user2 user3 
#vim /etc/httpd/conf/.htgroup----建立.htgroup組認證檔案內容如下 
        test: tom ning--------組名為test使用者為tom、ning


            自己測試就可以:再次不做說明,注意瀏覽器產生記錄。

瀏覽器:http://www.ning.com/liang

CGI指令碼----通用閘道介面

    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"------------指定CGI別名

     

  執行個體:在目錄/cgi-bin/目錄下建立ning.sh指令碼(預設系統是支援bash解析的)
        #!/bin/bash
        #
        cat << EOF
        Content-Type: text/html

        <pre>
        The hostname is : $(hostname).
        The date is : $(date).
        The IP is : $(ifconfig)

        </pre>
        EOF

在瀏覽器上輸入:172.16.3.20/cgi-bin/ning.sh

650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201408/10/1384120_1407678856DdDH.png" "539" height="429" />

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.