方式一
1. vi /etc/httpd/conf/httpd.conf
<Directory "/path/cross">
AuthName "Need Password"
AuthType Basic
AUthUserFile /path/htpasswd # 不需要與 /path/cross同一目錄
require valid-user
</Directory>
2. htpasswd -c /path/htpasswd cross
當新建htpasswd檔時,使用 -c 參數,建立第二位User時,不能再用"-c",否則會覆蓋
存帳號與密碼檔案為 htpasswd
使用者為 cross
參數
-c # 一開始建新檔時才要
-n # 只顯示結果,不要寫入檔案
-m # MD5加密
-d # crypt加密
-s # SHA加密
-p # plaintext
-D # 刪除使用者
方式二
1. vi /etc/httpd/conf/httpd.conf
#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#AccessFileName .htaccess
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#<Files ~ "^.ht">
Order allow,deny
Deny from all
</Files><Directory "/path/cross">
AllowOverride All
</Directory>
2. vi /path/cross/.htaccess
AuthName "Need Password"
AuthType Basic
AuthUserFile /path/cross/.htpasswd
require valid-user
3. htpasswd -c /path/cross/.htpasswd cross
留言