home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 May / PCWorld_2004-05_cd.bin / komunikace / apache / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F252342_auth.html.en < prev    next >
Extensible Markup Language  |  2003-05-29  |  21KB  |  351 lines

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
  4.         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  5.               This file is generated from xml source: DO NOT EDIT
  6.         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  7.       -->
  8. <title>Authentication, Authorization and Access Control - Apache HTTP Server</title>
  9. <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
  10. <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
  11. <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
  12. <link href="../images/favicon.ico" rel="shortcut icon" /></head>
  13. <body id="manual-page"><div id="page-header">
  14. <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
  15. <p class="apache">Apache HTTP Server Version 2.0</p>
  16. <img alt="" src="../images/feather.gif" /></div>
  17. <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
  18. <div id="path">
  19. <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs-project/">Documentation</a> > <a href="../">Version 2.0</a> > <a href="./">How-To / Tutorials</a></div><div id="page-content"><div id="preamble"><h1>Authentication, Authorization and Access Control</h1>
  20. <div class="toplang">
  21. <p><span>Available Languages: </span><a href="../en/howto/auth.html" title="English"> en </a> |
  22. <a href="../ja/howto/auth.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a></p>
  23. </div>
  24.  
  25.     <p>Authentication is any process by which you verify that
  26.     someone is who they claim they are. Authorization is any
  27.     process by which someone is allowed to be where they want to
  28.     go, or to have information that they want to have.</p>
  29. </div>
  30. <div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#related">Related Modules and Directives</a></li>
  31. <li><img alt="" src="../images/down.gif" /> <a href="#introduction">Introduction</a></li>
  32. <li><img alt="" src="../images/down.gif" /> <a href="#theprerequisites">The Prerequisites</a></li>
  33. <li><img alt="" src="../images/down.gif" /> <a href="#gettingitworking">Getting it working</a></li>
  34. <li><img alt="" src="../images/down.gif" /> <a href="#lettingmorethanonepersonin">Letting more than one
  35. person in</a></li>
  36. <li><img alt="" src="../images/down.gif" /> <a href="#possibleproblems">Possible problems</a></li>
  37. <li><img alt="" src="../images/down.gif" /> <a href="#whatotherneatstuffcanido">What other neat stuff can I
  38. do?</a></li>
  39. <li><img alt="" src="../images/down.gif" /> <a href="#moreinformation">More information</a></li>
  40. </ul></div>
  41. <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  42. <div class="section">
  43. <h2><a name="related" id="related">Related Modules and Directives</a></h2>
  44.     <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="../mod/mod_auth.html">mod_auth</a></code></li><li><code class="module"><a href="../mod/mod_access.html">mod_access</a></code></li></ul></td><td><ul><li><code class="directive"><a href="../mod/mod_access.html#allow">Allow</a></code></li><li><code class="directive"><a href="../mod/mod_auth.html#authgroupfile">AuthGroupFile</a></code></li><li><code class="directive"><a href="../mod/core.html#authname">AuthName</a></code></li><li><code class="directive"><a href="../mod/core.html#authtype">AuthType</a></code></li><li><code class="directive"><a href="../mod/mod_auth.html#authuserfile">AuthUserFile</a></code></li><li><code class="directive"><a href="../mod/mod_access.html#deny">Deny</a></code></li><li><code class="directive"><a href="../mod/core.html#options">Options</a></code></li><li><code class="directive"><a href="../mod/core.html#require">Require</a></code></li></ul></td></tr></table>
  45. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  46. <div class="section">
  47. <h2><a name="introduction" id="introduction">Introduction</a></h2>
  48.     <p>If you have information on your web site that is sensitive
  49.     or intended for only a small group of people, the techniques in
  50.     this article will help you make sure that the people that see
  51.     those pages are the people that you wanted to see them.</p>
  52.  
  53.     <p>This article covers the "standard" way of protecting parts
  54.     of your web site that most of you are going to use.</p>
  55. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  56. <div class="section">
  57. <h2><a name="theprerequisites" id="theprerequisites">The Prerequisites</a></h2>
  58.     <p>The directives discussed in this article will need to go
  59.     either in your main server configuration file (typically in a
  60.     <code class="directive"><a href="../mod/core.html#directory"><Directory></a></code> section), or
  61.     in per-directory configuration files (<code>.htaccess</code> files).</p>
  62.  
  63.     <p>If you plan to use <code>.htaccess</code> files, you will
  64.     need to have a server configuration that permits putting
  65.     authentication directives in these files. This is done with the
  66.     <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code> directive, which
  67.     specifies which directives, if any, may be put in per-directory
  68.     configuration files.</p>
  69.  
  70.     <p>Since we're talking here about authentication, you will need
  71.     an <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code> directive like the
  72.     following:</p>
  73.  
  74.     <div class="example"><p><code>
  75.       AllowOverride AuthConfig
  76.     </code></p></div>
  77.  
  78.     <p>Or, if you are just going to put the directives directly in
  79.     your main server configuration file, you will of course need to
  80.     have write permission to that file.</p>
  81.  
  82.     <p>And you'll need to know a little bit about the directory
  83.     structure of your server, in order to know where some files are
  84.     kept. This should not be terribly difficult, and I'll try to
  85.     make this clear when we come to that point.</p>
  86. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  87. <div class="section">
  88. <h2><a name="gettingitworking" id="gettingitworking">Getting it working</a></h2>
  89.     <p>Here's the basics of password protecting a directory on your
  90.     server.</p>
  91.  
  92.     <p>You'll need to create a password file. This file should be
  93.     placed somewhere not accessible from the web. This is so that
  94.     folks cannot download the password file. For example, if your
  95.     documents are served out of <code>/usr/local/apache/htdocs</code> you
  96.     might want to put the password file(s) in
  97.     <code>/usr/local/apache/passwd</code>.</p>
  98.  
  99.     <p>To create the file, use the <a href="../programs/htpasswd.html">htpasswd</a> utility that came
  100.     with Apache. This be located in the <code>bin</code> directory
  101.     of wherever you installed Apache. To create the file, type:</p>
  102.  
  103.     <div class="example"><p><code>
  104.       htpasswd -c /usr/local/apache/passwd/passwords rbowen
  105.     </code></p></div>
  106.  
  107.     <p><code>htpasswd</code> will ask you for the password, and
  108.     then ask you to type it again to confirm it:</p>
  109.  
  110.     <div class="example"><p><code>
  111.       # htpasswd -c /usr/local/apache/passwd/passwords rbowen<br />
  112.       New password: mypassword<br />
  113.       Re-type new password: mypassword<br />
  114.       Adding password for user rbowen
  115.     </code></p></div>
  116.  
  117.     <p>If <code>htpasswd</code> is not in your path, of course
  118.     you'll have to type the full path to the file to get it to run.
  119.     On my server, it's located at
  120.     <code>/usr/local/apache/bin/htpasswd</code></p>
  121.  
  122.     <p>Next, you'll need to configure the server to request a
  123.     password and tell the server which users are allowed access.
  124.     You can do this either by editing the <code>httpd.conf</code>
  125.     file or using an <code>.htaccess</code> file. For example, if
  126.     you wish to protect the directory
  127.     <code>/usr/local/apache/htdocs/secret</code>, you can use the
  128.     following directives, either placed in the file
  129.     <code>/usr/local/apache/htdocs/secret/.htaccess</code>, or
  130.     placed in <code>httpd.conf</code> inside a <Directory
  131.     /usr/local/apache/apache/htdocs/secret> section.</p>
  132.  
  133.     <div class="example"><p><code>
  134.       AuthType Basic<br />
  135.       AuthName "Restricted Files"<br />
  136.       AuthUserFile /usr/local/apache/passwd/passwords<br />
  137.       Require user rbowen
  138.     </code></p></div>
  139.  
  140.     <p>Let's examine each of those directives individually. The <code class="directive"><a href="../mod/core.html#authtype">AuthType</a></code> directive selects
  141.     that method that is used to authenticate the user. The most
  142.     common method is <code>Basic</code>, and this is the method
  143.     implemented by <code class="module"><a href="../mod/mod_auth.html">mod_auth</a></code>. It is important to be aware,
  144.     however, that Basic authentication sends the password from the client to
  145.     the browser unencrypted. This method should therefore not be used for
  146.     highly sensitive data. Apache supports one other authentication method:
  147.     <code>AuthType Digest</code>. This method is implemented by <code class="module"><a href="../mod/mod_auth_digest.html">mod_auth_digest</a></code> and is much more secure. Only the most recent
  148.     versions of clients are known to support Digest authentication.</p>
  149.  
  150.     <p>The <code class="directive"><a href="../mod/core.html#authname">AuthName</a></code> directive sets
  151.     the <dfn>Realm</dfn> to be used in the authentication. The realm serves
  152.     two major functions. First, the client often presents this information to
  153.     the user as part of the password dialog box. Second, it is used by the
  154.     client to determine what password to send for a given authenticated
  155.     area.</p>
  156.  
  157.     <p>So, for example, once a client has authenticated in the
  158.     <code>"Restricted Files"</code> area, it will automatically
  159.     retry the same password for any area on the same server that is
  160.     marked with the <code>"Restricted Files"</code> Realm.
  161.     Therefore, you can prevent a user from being prompted more than
  162.     once for a password by letting multiple restricted areas share
  163.     the same realm. Of course, for security reasons, the client
  164.     will always need to ask again for the password whenever the
  165.     hostname of the server changes.</p>
  166.  
  167.     <p>The <code class="directive"><a href="../mod/mod_auth.html#authuserfile">AuthUserFile</a></code>
  168.     directive sets the path to the password file that we just
  169.     created with <code>htpasswd</code>. If you have a large number
  170.     of users, it can be quite slow to search through a plain text
  171.     file to authenticate the user on each request. Apache also has
  172.     the ability to store user information in fast database files.
  173.     The <code class="module"><a href="../mod/mod_auth_dbm.html">mod_auth_dbm</a></code> module provides the <code class="directive"><a href="../mod/mod_auth_dbm.html#authdbmuserfile">AuthDBMUserFile</a></code> directive. These
  174.     files can be created and manipulated with the <a href="../programs/dbmmanage.html">dbmmanage</a> program. Many
  175.     other types of authentication options are available from third
  176.     party modules in the <a href="http://modules.apache.org/">Apache Modules
  177.     Database</a>.</p>
  178.  
  179.     <p>Finally, the <code class="directive"><a href="../mod/core.html#require">Require</a></code>
  180.     directive provides the authorization part of the process by
  181.     setting the user that is allowed to access this region of the
  182.     server. In the next section, we discuss various ways to use the
  183.     <code class="directive"><a href="../mod/core.html#require">Require</a></code> directive.</p>
  184. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  185. <div class="section">
  186. <h2><a name="lettingmorethanonepersonin" id="lettingmorethanonepersonin">Letting more than one
  187. person in</a></h2>
  188.     <p>The directives above only let one person (specifically
  189.     someone with a username of <code>rbowen</code>) into the
  190.     directory. In most cases, you'll want to let more than one
  191.     person in. This is where the <code class="directive"><a href="../mod/mod_auth.html#authgroupfile">AuthGroupFile</a></code> comes in.</p>
  192.  
  193.     <p>If you want to let more than one person in, you'll need to
  194.     create a group file that associates group names with a list of
  195.     users in that group. The format of this file is pretty simple,
  196.     and you can create it with your favorite editor. The contents
  197.     of the file will look like this:</p>
  198.  
  199.    <div class="example"><p><code>
  200.      GroupName: rbowen dpitts sungo rshersey
  201.    </code></p></div>
  202.  
  203.     <p>That's just a list of the members of the group in a long
  204.     line separated by spaces.</p>
  205.  
  206.     <p>To add a user to your already existing password file,
  207.     type:</p>
  208.  
  209.     <div class="example"><p><code>
  210.       htpasswd /usr/local/apache/passwd/password dpitts
  211.     </code></p></div>
  212.  
  213.     <p>You'll get the same response as before, but it will be
  214.     appended to the existing file, rather than creating a new file.
  215.     (It's the <code>-c</code> that makes it create a new password
  216.     file).</p>
  217.  
  218.     <p>Now, you need to modify your <code>.htaccess</code> file to
  219.     look like the following:</p>
  220.  
  221.     <div class="example"><p><code>
  222.       AuthType Basic<br />
  223.       AuthName "By Invitation Only"<br />
  224.       AuthUserFile /usr/local/apache/passwd/passwords<br />
  225.       AuthGroupFile /usr/local/apache/passwd/groups<br />
  226.       Require group GroupName
  227.     </code></p></div>
  228.  
  229.     <p>Now, anyone that is listed in the group <code>GroupName</code>,
  230.     and has an entry in the <code>password</code> file, will be let in, if
  231.     they type the correct password.</p>
  232.  
  233.     <p>There's another way to let multiple users in that is less
  234.     specific. Rather than creating a group file, you can just use
  235.     the following directive:</p>
  236.  
  237.     <div class="example"><p><code>
  238.       Require valid-user
  239.     </code></p></div>
  240.  
  241.     <p>Using that rather than the <code>Require user rbowen</code>
  242.     line will allow anyone in that is listed in the password file,
  243.     and who correctly enters their password. You can even emulate
  244.     the group behavior here, by just keeping a separate password
  245.     file for each group. The advantage of this approach is that
  246.     Apache only has to check one file, rather than two. The
  247.     disadvantage is that you have to maintain a bunch of password
  248.     files, and remember to reference the right one in the
  249.     <code class="directive"><a href="../mod/mod_auth.html#authuserfile">AuthUserFile</a></code> directive.</p>
  250. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  251. <div class="section">
  252. <h2><a name="possibleproblems" id="possibleproblems">Possible problems</a></h2>
  253.     <p>Because of the way that Basic authentication is specified,
  254.     your username and password must be verified every time you
  255.     request a document from the server. This is even if you're
  256.     reloading the same page, and for every image on the page (if
  257.     they come from a protected directory). As you can imagine, this
  258.     slows things down a little. The amount that it slows things
  259.     down is proportional to the size of the password file, because
  260.     it has to open up that file, and go down the list of users
  261.     until it gets to your name. And it has to do this every time a
  262.     page is loaded.</p>
  263.  
  264.     <p>A consequence of this is that there's a practical limit to
  265.     how many users you can put in one password file. This limit
  266.     will vary depending on the performance of your particular
  267.     server machine, but you can expect to see slowdowns once you
  268.     get above a few hundred entries, and may wish to consider a
  269.     different authentication method at that time.</p>
  270. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  271. <div class="section">
  272. <h2><a name="whatotherneatstuffcanido" id="whatotherneatstuffcanido">What other neat stuff can I
  273. do?</a></h2>
  274.     <p>Authentication by username and password is only part of the
  275.     story. Frequently you want to let people in based on something
  276.     other than who they are. Something such as where they are
  277.     coming from.</p>
  278.  
  279.     <p>The <code class="directive"><a href="../mod/mod_access.html#allow">Allow</a></code> and
  280.     <code class="directive"><a href="../mod/mod_access.html#deny">Deny</a></code> directives let
  281.     you allow and deny access based on the host name, or host
  282.     address, of the machine requesting a document. The
  283.     <code class="directive"><a href="../mod/mod_access.html#order">Order</a></code> directive goes
  284.     hand-in-hand with these two, and tells Apache in which order to
  285.     apply the filters.</p>
  286.  
  287.     <p>The usage of these directives is:</p>
  288.  
  289.     <div class="example"><p><code>
  290.       Allow from <var>address</var>
  291.     </code></p></div>
  292.  
  293.     <p>where <var>address</var> is an IP address (or a partial IP
  294.     address) or a fully qualified domain name (or a partial domain
  295.     name); you may provide multiple addresses or domain names, if
  296.     desired.</p>
  297.  
  298.     <p>For example, if you have someone spamming your message
  299.     board, and you want to keep them out, you could do the
  300.     following:</p>
  301.  
  302.     <div class="example"><p><code>
  303.       Deny from 205.252.46.165
  304.     </code></p></div>
  305.  
  306.     <p>Visitors coming from that address will not be able to see
  307.     the content covered by this directive. If, instead, you have a
  308.     machine name, rather than an IP address, you can use that.</p>
  309.  
  310.     <div class="example"><p><code>
  311.       Deny from <var>host.example.com</var>
  312.     </code></p></div>
  313.  
  314.     <p>And, if you'd like to block access from an entire domain,
  315.     you can specify just part of an address or domain name:</p>
  316.  
  317.     <div class="example"><p><code>
  318.       Deny from <var>192.101.205</var><br />
  319.       Deny from <var>cyberthugs.com</var> <var>moreidiots.com</var><br />
  320.       Deny from ke
  321.     </code></p></div>
  322.  
  323.     <p>Using <code class="directive"><a href="../mod/mod_access.html#order">Order</a></code> will let you be
  324.     sure that you are actually restricting things to the group that you want
  325.     to let in, by combining a <code class="directive"><a href="../mod/mod_access.html#deny">Deny</a></code>
  326.     and an <code class="directive"><a href="../mod/mod_access.html#allow">Allow</a></code> directive:</p>
  327.  
  328.     <div class="example"><p><code>
  329.       Order deny,allow<br />
  330.       Deny from all<br />
  331.       Allow from <var>dev.example.com</var>
  332.     </code></p></div>
  333.  
  334.     <p>Listing just the <code class="directive"><a href="../mod/mod_access.html#allow">Allow</a></code>
  335.     directive would not do what you want, because it will let folks from that
  336.     host in, in addition to letting everyone in. What you want is to let
  337.     <em>only</em> those folks in.</p>
  338. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  339. <div class="section">
  340. <h2><a name="moreinformation" id="moreinformation">More information</a></h2>
  341.     <p>You should also read the documentation for <code class="module"><a href="../mod/mod_auth.html">mod_auth</a></code>
  342.     and <code class="module"><a href="../mod/mod_access.html">mod_access</a></code> which contain some more information
  343.     about how this all works.</p>
  344. </div></div>
  345. <div class="bottomlang">
  346. <p><span>Available Languages: </span><a href="../en/howto/auth.html" title="English"> en </a> |
  347. <a href="../ja/howto/auth.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a></p>
  348. </div><div id="footer">
  349. <p class="apache">Maintained by the <a href="http://httpd.apache.org/docs-project/">Apache HTTP Server Documentation Project</a></p>
  350. <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>
  351. </body></html>