如何鎖定apache特定目錄權限

引用來自這位大哥的:http://www.ysps.tp.edu.tw/about/download/phpmyadmin/phpmyadmin.htm

密碼驗證

  可惜好花不常開,知道網址的任一使用者,都可以透過瀏覽器,管理你的SQL資料庫,這.....太不安全了吧。

  我們可以利用Apache提供的.htaccess存取限制功能,做簡易的使用者輸入密碼驗證。(聲明:這當然也不是很安全的做法),在/etc/httpd.conf 裡面,也要做好相關設定。

      更換目錄  cd  /home/httpd/html/phpMyAdmin 

 手動產生一個.htaccess 的隱藏檔

         qe  .htaccess (注意,.htaccess前面有一個點.,是隱藏檔)

   檔案內加入以下文字    

AuthName "private"                      //取一個名稱
    AuthType Basic                        //基本驗證
    AuthUserFile /security/user.pass  //驗證用的密碼檔路徑
    require user tester1 tester2    //指定誰可以使用 

 

然後用htpasswd 製作密碼檔,這要和.htaccess中指定的密碼檔路徑/security/user.pass配合喔。

    mkdir /security

    htpasswd  -c  /security/user.pass  tester1

輸入密碼兩次,確認tester1為使用者後,產生的密碼檔在 /security/user.pass

眼不見不信,一定要瞧一瞧去。

    cat  /security/user.pass

       tester1:ERWH0CVHJWCS

 

留言

熱門文章