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