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>htpasswd - Manage user files for basic authentication - 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" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" />
12<script src="/style/scripts/prettify.js" type="text/javascript">
13</script>
14
15<link href="/images/favicon.ico" rel="shortcut icon" /></head>
16<body id="manual-page"><div id="page-header">
17<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
18<p class="apache">Apache HTTP Server Version 2.2</p>
19<img alt="" src="/images/feather.gif" /></div>
20<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
21<div id="path">
22<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.2</a> &gt; <a href="./">Programs</a></div><div id="page-content"><div id="preamble"><h1>htpasswd - Manage user files for basic authentication</h1>
23<div class="toplang">
24<p><span>Available Languages: </span><a href="/en/programs/htpasswd.html" title="English">&nbsp;en&nbsp;</a> |
25<a href="/ko/programs/htpasswd.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
26<a href="/tr/programs/htpasswd.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
27</div>
28
29    <p><code>htpasswd</code> is used to create and update the flat-files used to
30    store usernames and password for basic authentication of HTTP users. If
31    <code>htpasswd</code> cannot access a file, such as not being able to write
32    to the output file or not being able to read the file in order to update it,
33    it returns an error status and makes no changes.</p>
34
35    <p>Resources available from the Apache HTTP server can be restricted to
36    just the users listed in the files created by <code>htpasswd</code>. This
37    program can only manage usernames and passwords stored in a flat-file. It
38    can encrypt and display password information for use in other types of data
39    stores, though. To use a DBM database see <code class="program"><a href="/programs/dbmmanage.html">dbmmanage</a></code>.</p>
40
41    <p><code>htpasswd</code> encrypts passwords using either a version of MD5
42    modified for Apache, or the system's <code>crypt()</code> routine. Files
43    managed by <code>htpasswd</code> may contain both types of passwords; some
44    user records may have MD5-encrypted passwords while others in the same file
45    may have passwords encrypted with <code>crypt()</code>.</p>
46
47    <p>This manual page only lists the command line arguments. For details of
48    the directives necessary to configure user authentication in
49    <code class="program"><a href="/programs/httpd.html">httpd</a></code> see the Apache manual, which is part of the
50    Apache distribution or can be found at <a href="http://httpd.apache.org">http://httpd.apache.org/</a>.</p>
51</div>
52<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#synopsis">Synopsis</a></li>
53<li><img alt="" src="/images/down.gif" /> <a href="#options">Options</a></li>
54<li><img alt="" src="/images/down.gif" /> <a href="#exit">Exit Status</a></li>
55<li><img alt="" src="/images/down.gif" /> <a href="#examples">Examples</a></li>
56<li><img alt="" src="/images/down.gif" /> <a href="#security">Security Considerations</a></li>
57<li><img alt="" src="/images/down.gif" /> <a href="#restrictions">Restrictions</a></li>
58</ul><h3>See also</h3><ul class="seealso"><li><code class="program"><a href="/programs/httpd.html">httpd</a></code></li><li>The scripts in support/SHA1 which come with the
59distribution.</li></ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
60<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
61<div class="section">
62<h2><a name="synopsis" id="synopsis">Synopsis</a></h2>
63    <p><code><strong>htpasswd</strong>
64    [ -<strong>c</strong> ]
65    [ -<strong>m</strong> ]
66    [ -<strong>D</strong> ] <var>passwdfile</var> <var>username</var></code></p>
67
68    <p><code><strong>htpasswd</strong> -<strong>b</strong>
69    [ -<strong>c</strong> ]
70    [ -<strong>m</strong> |
71      -<strong>d</strong> |
72      -<strong>p</strong> |
73      -<strong>s</strong> ] 
74    [ -<strong>D</strong> ]  <var>passwdfile</var> <var>username</var>
75    <var>password</var></code></p>
76
77    <p><code><strong>htpasswd</strong> -<strong>n</strong>
78    [ -<strong>m</strong> |
79      -<strong>d</strong> |
80      -<strong>s</strong> |
81      -<strong>p</strong> ] <var>username</var></code></p>
82
83    <p><code><strong>htpasswd</strong> -<strong>nb</strong>
84    [ -<strong>m</strong> |
85      -<strong>d</strong> |
86      -<strong>s</strong> |
87      -<strong>p</strong> ] <var>username</var> <var>password</var></code></p>
88</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
89<div class="section">
90<h2><a name="options" id="options">Options</a></h2>
91    <dl>
92    <dt><code>-b</code></dt>
93    <dd>Use batch mode; <em>i.e.</em>, get the password from the command line
94    rather than prompting for it. This option should be used with extreme care,
95    since <strong>the password is clearly visible</strong> on the command
96    line.</dd>
97
98    <dt><code>-c</code></dt>
99    <dd>Create the <var>passwdfile</var>. If <var>passwdfile</var> already
100    exists, it is rewritten and truncated. This option cannot be combined with
101    the <code>-n</code> option.</dd>
102
103    <dt><code>-n</code></dt>
104    <dd>Display the results on standard output rather than updating a file.
105    This is useful for generating password records acceptable to Apache for
106    inclusion in non-text data stores. This option changes the syntax of the
107    command line, since the <var>passwdfile</var> argument (usually the first
108    one) is omitted. It cannot be combined with the <code>-c</code> option.</dd>
109
110    <dt><code>-m</code></dt>
111    <dd>Use MD5 encryption for passwords. This is the default (since version
112    2.2.18).</dd>
113
114    <dt><code>-d</code></dt>
115    <dd>Use <code>crypt()</code> encryption for passwords. This is not
116    supported by the <code class="program"><a href="/programs/httpd.html">httpd</a></code> server on Windows and
117    Netware and TPF.  This algorithm limits the password length to 8
118    characters.  This algorithm is <strong>insecure</strong> by today's
119    standards.  It used to be the default algorithm until version 2.2.17.</dd>
120
121    <dt><code>-s</code></dt>
122    <dd>Use SHA encryption for passwords. Facilitates migration from/to Netscape
123    servers using the LDAP Directory Interchange Format (ldif).</dd>
124
125    <dt><code>-p</code></dt>
126    <dd>Use plaintext passwords. Though <code>htpasswd</code> will support
127    creation on all platforms, the <code class="program"><a href="/programs/httpd.html">httpd</a></code> daemon will
128    only accept plain text passwords on Windows, Netware and TPF.</dd>
129
130    <dt><code>-D</code></dt>
131    <dd>Delete user. If the username exists in the specified htpasswd file, it
132    will be deleted.</dd>
133    
134    <dt><code><var>passwdfile</var></code></dt>
135    <dd>Name of the file to contain the user name and password. If
136    <code>-c</code> is given, this file is created if it does not already exist,
137    or rewritten and truncated if it does exist.</dd>
138
139    <dt><code><var>username</var></code></dt>
140    <dd>The username to create or update in <var>passwdfile</var>. If
141    <var>username</var> does not exist in this file, an entry is added. If it
142    does exist, the password is changed.</dd>
143
144    <dt><code><var>password</var></code></dt>
145    <dd>The plaintext password to be encrypted and stored  in the file. Only
146    used with the <code>-b</code> flag.</dd>
147    </dl>
148</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
149<div class="section">
150<h2><a name="exit" id="exit">Exit Status</a></h2>
151    <p><code>htpasswd</code> returns a zero status ("true") if the username and
152    password have been successfully added or updated in the
153    <var>passwdfile</var>. <code>htpasswd</code> returns <code>1</code> if it
154    encounters some problem accessing files, <code>2</code> if there was a
155    syntax problem with the command line, <code>3</code> if the password was
156    entered interactively and the verification entry didn't match,
157    <code>4</code> if its operation was interrupted, <code>5</code> if a value
158    is too long (username, filename, password, or final computed record),
159    <code>6</code> if the username contains illegal characters (see the
160    <a href="#restrictions">Restrictions section</a>), and <code>7</code>
161    if the file is not a valid password file.</p>
162</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
163<div class="section">
164<h2><a name="examples" id="examples">Examples</a></h2>
165    <div class="example"><p><code>
166      htpasswd /usr/local/etc/apache/.htpasswd-users jsmith
167    </code></p></div>
168
169    <p>Adds or modifies the password for user <code>jsmith</code>. The user
170    is prompted for the password. The password will be encrypted using the
171    modified Apache MD5 algorithm. If the file does not exist,
172    <code>htpasswd</code> will do nothing except return an error.</p>
173
174    <div class="example"><p><code>
175      htpasswd -c /home/doe/public_html/.htpasswd jane
176    </code></p></div>
177
178    <p>Creates a new file and stores a record in it for user <code>jane</code>.
179    The user is prompted for the password. If the file exists and cannot be
180    read, or cannot be written, it is not altered and <code>htpasswd</code>
181    will display a message and return an error status.</p>
182
183    <div class="example"><p><code>
184      htpasswd -db /usr/web/.htpasswd-all jones Pwd4Steve
185    </code></p></div>
186
187    <p>Encrypts the password from the command line (<code>Pwd4Steve</code>)
188    using the <code>crypt()</code> algorithm, and stores it in the specified
189    file.</p>
190</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
191<div class="section">
192<h2><a name="security" id="security">Security Considerations</a></h2>
193    <p>Web password files such as those managed by <code>htpasswd</code> should
194    <em>not</em> be within the Web server's URI space -- that is, they should
195    not be fetchable with a browser.</p>
196
197    <p>This program is not safe as a setuid executable. Do <em>not</em> make it
198    setuid.</p>
199
200    <p>The use of the <code>-b</code> option is discouraged, since when it is
201    used the unencrypted password appears on the command line.</p>
202
203    <p>When using the <code>crypt()</code> algorithm, note that only the first
204    8 characters of the password are used  to form the password. If the supplied
205    password is longer, the extra characters will be silently discarded.</p>
206
207    <p>The SHA encryption format does not use salting: for a given password,
208    there is only one encrypted representation. The <code>crypt()</code> and
209    MD5 formats permute the representation by prepending a random salt string,
210    to make dictionary attacks against the passwords more difficult.</p>
211</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
212<div class="section">
213<h2><a name="restrictions" id="restrictions">Restrictions</a></h2>
214    <p>On the Windows and MPE platforms, passwords encrypted with
215    <code>htpasswd</code> are limited to no more than <code>255</code>
216    characters in length. Longer passwords will be truncated to 255
217    characters.</p>
218
219    <p>The MD5 algorithm used by <code>htpasswd</code> is specific to the Apache
220    software; passwords encrypted using it will not be usable with other Web
221    servers.</p>
222
223    <p>Usernames are limited to <code>255</code> bytes and may not include the
224    character <code>:</code>.</p>
225</div></div>
226<div class="bottomlang">
227<p><span>Available Languages: </span><a href="/en/programs/htpasswd.html" title="English">&nbsp;en&nbsp;</a> |
228<a href="/ko/programs/htpasswd.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
229<a href="/tr/programs/htpasswd.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
230</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
231<script type="text/javascript"><!--//--><![CDATA[//><!--
232var comments_shortname = 'httpd';
233var comments_identifier = 'http://httpd.apache.org/docs/2.2/programs/htpasswd.html';
234(function(w, d) {
235    if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
236        d.write('<div id="comments_thread"><\/div>');
237        var s = d.createElement('script');
238        s.type = 'text/javascript';
239        s.async = true;
240        s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
241        (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
242    }
243    else { 
244        d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
245    }
246})(window, document);
247//--><!]]></script></div><div id="footer">
248<p class="apache">Copyright 2013 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
249<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
250if (typeof(prettyPrint) !== 'undefined') {
251    prettyPrint();
252}
253//--><!]]></script>
254</body></html>