一、建立.htaccess檔案
首先login cyber.cs.ntou.edu.tw,在你要保護的目錄下建立一個名為.htaccess 內容為
複製程式
# 隨便取個名字吧,它會出?#123;在瀏覽器的蹦出視窗中。
AuthName 國立臺灣海洋大學資訊系通訊錄查詢
# 編碼方式,目前只支援Basic一種而已。
AuthType Basic
# 密碼檔的絕對路徑,可用htpasswd指令建立
# (.htpasswd檔可在ind.ntou.edu.tw上建好再傳回cyber.cs.ntou.edu.tw)。
AuthUserFile /home/under/b86204/.htpasswd
#^^^^^
#自己的帳戶名
# 若下面有指定 require group,則需要group檔的絕對路徑。
# AuthGroupFile /home/under/b86204/filename
<Limit GET POST>
require user franklin
require user beef
require user david
require user huangant
#^^^^^^^^^
#可?#91;看你的Project的username
#require group my-users group2 ...
</Limit>
AuthGroupFile 檔案內容範例]franklin:Z4vr73LqdneRA
beef:RVN7zpfopMpiY
davidɈmUlggYxqB4KQ
huangant:DtAmaQ49hJuWk [/code]
^^^^^^^^^^^^^^^^^^^^
usernamegcrypt編碼過的密碼
當然最簡單的方法,就是 telnet ind.ntou.edu.tw這台主機, 利用htpasswd程式建立.htpasswd,再傳回cyber.cs.ntou.edu.tw。 方法如下所示] % telnet ind.ntou.edu.tw
(login的過?#123;略)
% htpasswd -c htpasswd.txt franklin
Adding password for franklin
New password:
Re-type new password:
% htpasswd htpasswd.txtbeef
Adding user beef
New password:
Re-type new password:
(其餘的username 之密碼建立,如同"htpasswd htpasswd.txt beef"一般,
以此類推。如果 htpasswd ?#123;式有任何疑問,不妨用"htpasswd -h"查查)
%ftp cyber.cs.ntou.edu.tw
(ftp過?#123;略)
ftp>mput htpasswd.txt
ftp>bye
%telnet cyber.cs.ntou.edu.tw
(login過?#123;略)
% mv htpasswd.txt .htpasswd[/code]
三、要如何在Homepage或CGI辨識那一個user在瀏覽此一加密的目錄? 不外乎要使用環境變數,但是需要一些前置作業]% cp /usr/local/etc/httpd/cgi-bin/w3-msql ~/www/project
^^^^^^^^^^^^^
Project location
% mv ~/www/project/w3-msql ~/www/project/w3-msql.cgi[/code]
在你呼叫含有w3-msql語法的html檔時,要用
複製程式
"http://cyber.cs.ntou.edu.tw/~b86204/project/w3-msql.cgi/~b86204/project/project.html"
^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
your cgi your project file
如此一來,就可以在w3-msql中,用$REMOTE_USER得知目前的user是誰了。
四、如何限制某些 domain 的存取
複製程式
AuthName Example
AuthType Basic
AuthUserFile /home/under/b86204/.htpasswd
AuthGroupFile /home/under/b86204/filename
<Limit GET>
order deny, allow
deny from all
allow from .ntou.edu.tw
</Limit>