您的位置:首页 > 运维架构 > Apache

Apache的认证机制

2014-02-18 19:38 411 查看
apache支持的认证机制: basic认证:账号密码使用明文传输,所以很不安全,但是要结合ssl来使用的话比较安全,basic是根据目录(目录及其子目录)进行认证的。 摘要认证:使用md5或者sha1加密密码,然后在网络上进行传输,安全性提高了,但是不被广大浏览器所支持,所以使用的很少。 表单认证:需要在用户登录的时候给用户提示表单,要求用户在表单上输入完用户和密码以后才可以登录,都是不容易实现。
下面都是以basic来进行测试实验
File文本格式的存储密码文件:[root@Wiker www]# pwd/var/www[root@Wiker www]#mkdir stuff[root@Wiker www]# vim/etc/httpd/conf/httpd.conf alias /stuff/"/var/www/stuff/"<Directory"/var/www/stuff"> Options none AllowOverride AuthConfig Authtype basic Authname "stuff" AuthBasicProvider file Authuserfile /etc/httpd/conf/.htpasswd Require valid-user</Directory>[root@Wiker www]#echo "Stuff" >/var/www/stuff/index.html[root@Wiker www]#service httpd restartStopping httpd: [ OK ]Starting httpd: [ OK ][root@Wiker www]# htpasswd -c -m /etc/httpd/conf/.htpasswd wiker #初次使用的时候加上-c进行初始化New password: Re-type new password:Adding password foruser wiker[root@Wiker www]# cat/etc/httpd/conf/.htpasswd wiker:$apr1$31wnUozp$Roa/3JAGg0zgV8Wom/UB60然后客户端打开http://192.168.0.1/stuff/

正确输入完用户名和密码以后就可以打开了

如果允许组中的成员都可以访问[root@Wiker www]# vim/etc/httpd/conf/httpd.confalias /stuff/"/var/www/stuff/"<Directory"/var/www/stuff"> Options none AllowOverride AuthConfig Authtype basic Authname "stuff" AuthBasicProvider file Authuserfile /etc/httpd/conf/.htpasswd Authgroupfile /etc/httpd/conf/.htgroup Require group mystuffs</Directory>[root@Wiker www]#htpasswd -m /etc/httpd/conf/.htpasswd testNew password: Re-type new password:Adding password foruser test[root@Wiker www]#htpasswd -m /etc/httpd/conf/.htpasswd userNew password: Re-type new password:Adding password foruser user[root@Wiker www]# vim/etc/httpd/conf/.htgroupmystuffs:wiker test[root@Wiker www]#service httpd restartStopping httpd: [ OK ]Starting httpd: [ OK ]然后用其他的浏览器再访问这个页面,不要使用刚才的浏览器,然后用户名和密码我们不输入那个组里面的

他就会提示我们再次输入(因为密码不正确),然后这次我们输入组里面的账号,然后就可以看到里面的信息了



DBM格式存储密码文件:普通情况下,用户和密码的提供者使用的是文本格式,所以不安全,我们可以使用dbm格式的数据库提来提高安全性[root@Wiker ~]# vim/etc/httpd/conf/httpd.conf alias /stuff/"/var/www/stuff/"<Directory"/var/www/stuff"> Options none AllowOverride AuthConfig Authtype basic Authname "stuff" AuthbasicProvider dbm Authdbmuserfile /etc/httpd/conf/.stuff.dbm Require valid-user</Directory>[root@Wiker ~]# htdbm-c -m /etc/httpd/conf/.stuff.dbm dbmuserEnter password : Re-type password : Database/etc/httpd/conf/.stuff.dbm created.[root@Wiker ~]# htdbm-m /etc/httpd/conf/.stuff.dbm redhatEnter password : Re-type password : Database/etc/httpd/conf/.stuff.dbm updated.[root@Wiker ~]# file /etc/httpd/conf/.stuff.dbm.* #密码文件是一个二进制文件,无法直接查看/etc/httpd/conf/.stuff.dbm.dir:empty/etc/httpd/conf/.stuff.dbm.pag:data[root@Wiker ~]# httpd-tSyntax OK[root@Wiker ~]#service httpd restartStopping httpd: [ OK ]Starting httpd: [ OK ]然后使用浏览器打开http://192.168.0.1/stuff/,不要使用之前的浏览器

然后就可以看到里面的页面了



本文出自 “IT没有圈” 博客,请务必保留此出处http://wiker.blog.51cto.com/8481872/1360233
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: