htpasswd -c /home/httpd/secr/.htpasswd super
此程序会询问用户"super"的口令,你输入"fill-06",两次生效。
建立.htaccess文件
用vi在/home/httpd/html/backup/目录下建立一个文件.htaccess,写入
以下几行:
AuthName My Friend Only (注:这个名字是任取的)
AuthType Basic
AuthUserFile /home/httpd/secr/.htpasswd
require user super
设置文件权限,确保Apache用户有读的权限
这样就完成了设置工作,你可以试一试效果了。
实例二:允许一组用户访问一个目录
假设,www.xxx.com想让myfriend组中的mf1与mf2两个用户分别能
使用口令"mf001-1""mf002-2"访问/home/httpd/html/backup/目录。
实现步骤:
使用htpasswd建立用户文件
htpasswd -c /home/httpd/secr/.htpasswd mf1
htpasswd -c /home/httpd/secr/.htpasswd mf2
建立组文件
用vi/home/httpd/secr/目录下建立一个文件.htgroup,写入:
myfriend:mf1 mf2
建立.htaccess文件
用vi在/home/httpd/html/backup/目录下建立一个文件.htaccess,写入
以下几行:
AuthName My Friend Only
AuthType Basic
AuthUserFile /home/httpd/secr/.htpasswd
AuthGroupFile /home/httpd/secr/.htgroup
require group myfriend
配置工作到此结束,试一试吧!
实例三:混合使用基于主机与基于用户名/口令的认证方式
如果你除了只允许让mf1与mf2两个用户访问外,还想禁www.wonlu.com
外的主机访问这个目录的话,就将/home/httpd/html/backup/.htaccess修改成
为:
AuthName My Friend Only