-->
apache的基本认证的密码是通过命令htpasswd来生成的,方法如下:
[supersun@supersun.biz conf]$../bin/htpasswd -bc password
supersun hello
[supersun@supersun.biz conf]$cat password
supersun:Pajgyd5fZISUs
有时手头没有htpasswd这个命令,或者给别人建个账号而不想知道别人的密码,这时我们只需要将别人发过来的密码加密串添到加password文件中就行。这里有一个perl的加密脚本crypt.pl,内容如下:
#!/usr/bin/perl
use strict;
my $passWord=$ARGV[0];
print crypt($passWord,$passWord)."\n";
运行perl crypt.pl hello
[supersun@supersun.biz ~]$ perl crypt.pl hello
heFw0NKyvGSTg
然后将加密串和账号添加到password中。
httpd.conf中的配置为如下格式
<Location />
AuthType
Basic
AuthName
"hello"
AuthUserFile /home/apache/conf/password
Require
valid-user
</Location>
原文见:http://bash.cyberciti.biz/web-server/htpasswd-replacement-perl-script/

发表评论