Basic认证

basic认证:

(1) 定义安全域

[root@bluee htdocs]# mkdir admin

[root@bluee htdocs]# vim admin/index.html

刷新浏览器,可以看到admin/index.html文件内容“Page FOR Adminstration”

编辑配置文件:

找个位置增加一个Directoty:

<Directory "/www/htdocs/admin">

    Options None

    AllowOverride None

    AuthType Basic

    AuthName "Administrator private"

    AuthUserFile "/etc/httpd/conf.d/.htpasswd"

    Require valid-user

</Directory>

保存退出,reload

刷新浏览器,会跳出对话框,让你输入用户名,密码。

(2) 提供账号和密码存储(文本文件)

创建2个用户,tom,jerry:

[root@bluee htdocs]# htpasswd -c -m /etc/httpd/conf.d/.htpasswd tom

New password: 

Re-type new password: 

Adding password for user tom

[root@bluee htdocs]# htpasswd -m /etc/httpd/conf.d/.htpasswd jerry

New password: 

Re-type new password: 

Adding password for user jerry

[root@bluee htdocs]# tail /etc/httpd/conf.d/.htpasswd

tom:$apr1$uVF1Y2Md$4nvTGjFgHkDQmtWqtns5C/

jerry:$apr1$2a/r7qbi$08LEFNgWKCcfn0oCJKaUg0

[root@bluee htdocs]#

浏览器的对话框中输入账号:tom,密码:tom,可以登陆。

换个浏览器,仍然会提示登陆的。

配置文件中Require valid-user  改为 Require user tom,

reload

再次打开浏览器,输入jerry的账号,密码,并不能登陆。tom的账号密码是可以登陆的。

(3) 实现基于组进行认证

要提供:用户账号文件和组文件;

再创建个用户,obama:

htpasswd -m /etc/httpd/conf.d/.htpasswd obama

New password: 

Re-type new password: 

Adding password for user obama

[root@bluee htdocs]# tail /etc/httpd/conf.d/.htpasswd

tom:$apr1$uVF1Y2Md$4nvTGjFgHkDQmtWqtns5C/

jerry:$apr1$2a/r7qbi$08LEFNgWKCcfn0oCJKaUg0

obama:$apr1$IRjBDVjX$cQwfp8jt9mZ0uWVqyaVlU0

vim /etc/httpd/conf.d/.htgroup

webadmin: jerry obama

保存退出,

reload

修改配置文件,

添加一行:AuthGroupFile "/etc/httpd/conf.d/.htgroup"

并修改为:Require webadmin

<Directory "/www/htdocs/admin">

    Options None

    AllowOverride None

    AuthType Basic

    AuthName "Administator private"

    AuthUserFile "/etc/httpd/conf.d/.htpasswd"

    AuthGroupFile "/etc/httpd/conf.d/.htgroup"

    Require group webadmin

</Directory>

刷新浏览器,输入账号密码,jerry ,obama是可以访问的。

原创文章,作者:mississippi,如若转载,请注明出处:http://www.178linux.com/27904

(0)
mississippimississippi
上一篇 2016-08-05 16:17
下一篇 2016-08-05 16:17

相关推荐

  • 博客作业网络班22期+第5周(9.5-9.11)

    1、显示当前系统上root、fedora或user1用户的默认shell [root@MyCloudServer wjb]# egrep '^(root|fedora|user1)\>' /etc/passwd | cut -d: -f7/bin/bash 2、找出/etc/rc.d/init.d/functions文件中某单词后面…

    Linux干货 2016-09-15
  • nginx配置(二)

    ngx_http_gzip_module: The ngx_http_gzip_module module is a filter that compresses responses using the “gzip” method. This often helps to reduce the size of transmitted data by half…

    Linux干货 2017-05-08
  • Linux基础概念和基础命令

    计算机基础:     一、计算机系统组成               二、冯诺依曼体系              三、服务器存储类…

    Linux干货 2016-07-22
  • 记录Linux入门3天,每天的点点滴滴记录

        Linux 文件系统的特性:      1、文件名严格区分字符大小写      2、文件名可以使用除了 /  意外任意的字符,但不建议使用特殊字符      3、文件名长度不能超过255个字符     &nbsp…

    Linux干货 2017-05-21
  • Homework Week-2 Linux文件管理

    1、Linux上的文件管理命令都有哪些,其常用的使用方法及其相关示例演示。 文件管理工具:cp, mv, rm         cp命令:copy  源文件  目标文件                单源复制:cp [O…

    Linux干货 2016-08-22
  • 安装RPM包 rpm与yum工具的使用

    1.认识yum与rpm工具.                 在windows下安装一个软件很轻松,只要双击.exe的文件,安装提示连续 “下一步” 即可,然而linux系统下安装一个软件似乎并不那么轻松了,因为我们不是在图形界面下。所以你要学会如何在linux下安装一…

    Linux干货 2016-08-26