httpd基于用户的访问控制

本文详细介绍如何使用auth_basic_module模块实现基于用户和组的HTTP认证。包括使用htpasswd命令创建http用户,配置Apache服务来限制对特定目录的访问,以及通过不同方式验证用户身份。

auth_basic_module 的应用

创建http用户

-- 基于用户
cd /etc/httpd/conf.d/
htpasswd -c .authfile zs
htpasswd .authfile ls

-- 基于组
cd /etc/httpd/conf.d/
vim .httpgroup
g1: zs ls
g2: ww zl
htpasswd -c .authfile zs
htpasswd .authfile ls
htpasswd .authfile ww
htpasswd .authfile zl

创建目录、主页面

mkdir /var/www/html/admin
echo admin > /var/www/html/admin/index.html

配置文件

-- 基于用户
vim /etc/httpd/conf.d/test.conf
<Directory "/var/www/html/admin">
	authtype basic
	authname "admin path"
	authuserfile "/etc/httpd/conf.d/.authfile"
	require user zs // requre valid-user 
</Directory>

-- 基于用户    或者用下面这个配置也可以
 vim /var/www/html/admin/.htaccess
 	authtype basic
	authname "admin path"
	authuserfile "/etc/httpd/conf.d/.authfile"
vim /etc/httpd/conf.d/test.conf
<Directory "/var/www/html/admin">
	allowoverride authconfig
</Directory>

-- 基于组
vim /etc/httpd/conf.d/test.conf
<Directory "/var/www/html/admin">
	authtype basic
	authname "admin path"
	authuserfile "/etc/httpd/conf.d/.authfile"
	authgroupfile "/etc/httpd/conf.d/.httpgroup"
	require group g1
</Directory>

启动服务

httpd -t
systemctl restart httpd

测试
在这里插入图片描述

htpasswd 命令

htpasswd [options] /PATH/HTTPD_PASSWD_FILE username
-c  自动创建文件,仅应该在文件不存在时使用
-p  明文密码
-d  CRYPT格式加密,默认
-m  md5格式加密
-s sha格式加密
-D  删除指定用户
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值