Apache web server如果使用basic authentication就需要管理password文件,该文件用htpasswd命令管理。这个命令位于$Apache_Home/bin.
具体使用方法可以用 "htpasswd help"来看,打出来的说明如下,Usage:
htpasswd [-cmdpsD] passwordfile username
htpasswd -b[cmdpsD] passwordfile username password
htpasswd -n[mdps] username
htpasswd -nb[mdps] username password
-c Create a new file.
-n Don't update file; display results on stdout.
-m Force MD5 encryption of the password (default).
-d Force CRYPT encryption of the password.
-p Do not encrypt the password (plaintext).
-s Force SHA encryption of the password.
-b Use the password from the command line rather than prompting for it.
-D Delete the specified user.
On Windows, NetWare and TPF systems the '-m' flag is used by default.
On all other systems, the '-p' flag will probably not work.
常用的命令如下:
htpasswd -bc password jim testpwd
在$Apache_Home/bin下创建password文件,并创建用户jim,密码是testpwd
htpasswd password kay
添加另一个用户kay,会提示输入密码,默认MD5加密
htpasswd -D password kay
删除kay
P.S. Basic authentication的例子:
<Directory "F:\apps\myapp\htdocs">
AuthType Basic
AuthName phpMyAdmin
AuthUserFile "F:\apps\myapp\apache2\users"
Require valid-user
Order allow,deny
Allow from 127.0.0.1
Satisfy all
ErrorDocument 403 /pmaforbidden.html
</Directory>