每天更改htaccess密码

我想保护一个子域名,用户只能访问1天。 是否可以设置一个cron作业,每天使用新密码自动更新一个.htpasswd文件?

你应该使用一个应用程序来完成这个任务,而不是用cron攻击一些东西。 但是,如果你必须使它变得可笑

您将不得不在“批处理模式”下运行htpasswd。 从htpasswd手册页:

htpasswd -mb /usr/web/.htpasswd-all jones Pwd4Steve Encrypts the password from the command line (Pwd4Steve) using the MD5 algorithm, and stores it in the specified file. 

像这样的东西应该工作:

 FILE=/path/to/your/htaccess/file # There are a bunch of ways to get a new password, this is one: NEW_PASS=`cat /dev/urandom|tr -dc "a-zA-Z0-9-_\$\?"|fold -w 9|head -n1` HTPASSWD=/usr/bin/htpasswd WEB_USER=samuel_l_jackson # This should do it $HTPASSWD -b $FILE $WEB_USER $NEW_PASS # You'll probably want to email the password to your user, # so they can actually use the new password 

通常我只会回答:是的,这是可能的。

但是你甚至可以集成一个存储用户和密码的数据库。 例如mod_auth_mysql 。 然后你甚至可以使用标准的SQL来启用/禁用/修改所有的东西。 我只会给这个问题和主页留下一个提示。 有时候这种方法不起作用,但是在这种情况下,你可以用mod_auth_mysqlreplacemod_auth_mysql ,然后把MySQL的东西集成到PAM中。 但是我会把这个作为读者的练习。