在 Ubuntu 上,Apache2 本身没有“用户密码”这个概念,你大概率是遇到了下面几种情况之一。我按常见场景给你说明怎么“重置”。
Apache 是跑在系统用户下的,如果你是说进不了服务器 / sudo 要用密码:
root shellmount -o remount,rw /
passwd 用户名
reboot
常见于:
http://ip/admin 弹出账号密码AuthType Basic找到 .htpasswd 文件(通常在 /etc/apache2/ 下):
sudo htpasswd -c /etc/apache2/.htpasswd 用户名
-c 是新建(会覆盖)-c 是修改已有用户示例:
sudo htpasswd /etc/apache2/.htpasswd admin
然后重启 Apache:
sudo systemctl restart apache2
如果其实是数据库密码忘了:
sudo systemctl stop mysql
sudo mysqld_safe --skip-grant-tables &
mysql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
然后重启 MySQL。
那是 MySQL 用户密码,不是 Apache 的。
sudo apt install apache2-utils
sudo htpasswd -c /etc/apache2/.htpasswd user1
Apache 配置里加:
<Directory /var/www/html/admin>
AuthType Basic
AuthName "Restricted"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
如果你能告诉我:
我可以直接给你精确命令。