htpasswd Command: Create Users With bcrypt (Examples)
The htpasswd command writes username:hash lines for Apache Basic Auth. bcrypt is -B. FlashKit’s htpasswd generator does not implement bcrypt: it outputs SHA-1 {SHA} or a plain line, hashed with Web Crypto in this tab. Use the CLI when you need $2y$.
Manual: htpasswd (Apache 2.4). Formats: Password Formats. Commands below were run on Debian-family apache2-utils 2.4.58 with throwaway passwords. Do not reuse those strings.
htpasswd command examples (real CLI output)
Create a file with bcrypt, then verify, add a second user, print a line, delete:
htpasswd -c -B -b htpasswd-demo demo 'Throwaway!2026a'
# Adding password for user demo
# demo:$2y$05$oydELnfJ.TzEMxJzkBUt8eDmmcgWH7ZBS/vAJ5K6H094GYR5SkXlm
htpasswd -vb htpasswd-demo demo 'Throwaway!2026a'
# Password for user demo correct. (exit 0)
htpasswd -vb htpasswd-demo demo 'wrong-password'
# password verification failed (exit 3)
htpasswd -B -b htpasswd-demo staging 'AnotherThrowaway!9'
# Adding password for user staging
htpasswd -nB -b cliuser 'CliThrowaway!3'
# cliuser:$2y$05$dPB00A1dIHvIRMceMoBZ8eHM6oEBbXAv3Bo5bxW4dPkrMZVu3X3GW
htpasswd -nbs sha1user 'password123'
# sha1user:{SHA}y/2sYAj5yrQIN4TL0YdPdmGNKpc=
htpasswd -D htpasswd-demo staging
# Deleting password for user staging
Bcrypt hashes include a salt; yours will not match these bytes if you re-run -B. The SHA-1 line for password123 is stable: FlashKit’s SHA mode produces the same {SHA}y/2sYAj5yrQIN4TL0YdPdmGNKpc= for that password because SHA-1 has no salt (Apache’s manual calls SHA less secure than MD5-crypt for that reason).
Need a {SHA} line without Apache?
Local SHA-1 or plain. Not bcrypt. Close the tab on a shared computer.
Open the htpasswd generatorWithout a full Apache install, and what belongs in .htaccess
On Debian/Ubuntu, sudo apt install apache2-utils gives you htpasswd without enabling the web server. Fedora/RHEL: httpd-tools. -n prints a line you can append yourself. -p (plaintext) printed plainuser:password123 here and a warning that storing passwords as plain text might not work on this platform — do not deploy that.
The file is not enough: Apache still needs AuthType Basic, AuthUserFile, and Require valid-user. Draft related redirects with the .htaccess generator (it does not emit AuthType). Folder walkthrough: password-protect a folder. HTTPS/www rules: htaccess HTTPS and www. Generate the password itself with the password generator before you hash it.
Generate the password, then hash it
Local CSPRNG. Then htpasswd -B on the server, or {SHA} in the lab generator.
Open the password generatorFlags worth memorizing, and what FlashKit cannot do
Apache’s htpasswd man page (httpd.apache.org/docs/current/programs/htpasswd.html) is the source for the flags used above. -c creates a new file and will overwrite an existing one if you pass it again — that is how you wipe a lab file by accident. -b takes the password from the command line; it is convenient for scripts and visible in process lists, so skip it on a shared host. -n prints the line to stdout instead of writing a file. -B is bcrypt; -m is Apache MD5 (apr1); -s is SHA-1 with the {SHA} prefix; -p is plaintext. -D deletes a user. -v verifies.
FlashKit’s generator offers two algorithms: SHA-1 ({SHA} + Base64 of the SHA-1 digest) and plaintext. There is no bcrypt option in the browser tool. If a search for “htpasswd bcrypt” landed here, the command-line -B examples are the ones to copy, not the generator’s output. A bcrypt hash from Apache on this machine for the throwaway password started $2y$05$; yours will differ because of the salt. The SHA-1 line for password123 is stable and matches the generator: {SHA}y/2sYAj5yrQIN4TL0YdPdmGNKpc=.
Do not paste production passwords into a web form on a shared computer. The generator runs in the tab, but the page is still a web page. For anything that will sit in front of a directory of real users, run htpasswd -B on the server that will serve the file, keep the file outside the document root, and put AuthUserFile in the Apache config or in a .htaccess that also has AuthType Basic and Require valid-user. The FlashKit .htaccess generator drafts redirects and HTTPS rules; it does not emit those Auth* directives.
Nginx, and a check you can run
Nginx does not read Apache’s htpasswd file format in every module the same way Apache does. auth_basic_user_file commonly accepts crypt, apr1, and bcrypt depending on how nginx was built; SHA-1 {SHA} is the format the browser tool emits and is the weaker option Apache itself documents. Prefer bcrypt created with htpasswd -B (or openssl passwd -apr1 only if you must). The folder-protection guide walks Apache and nginx side by side; this page stays on the command that writes the file.
After you add a user, verify before you reload Apache: htpasswd -vb file user password should print “Password for user … correct.” and exit 0. A wrong password exits 3 in the run above. Then confirm the vhost still points AuthUserFile at that path. A hash that verifies on the CLI but 401s in the browser is almost always a path, a realm mismatch, or HTTPS not reaching the same vhost — not a bcrypt vs SHA debate.
SHA-1 in the browser vs bcrypt on the server
FlashKit’s htpasswd generator has two modes: SHA-1 and plaintext. SHA-1 writes {SHA} plus Base64 of the SHA-1 digest of the password. For the throwaway password123 that line is {SHA}y/2sYAj5yrQIN4TL0YdPdmGNKpc=, the same string Apache printed with htpasswd -nbs. There is no salt, so two users with the same password get the same hash. Apache’s own documentation treats SHA as less secure than MD5-crypt for that reason, and bcrypt as the current -B choice.
Plaintext mode writes user:password with no hash. Apache’s -p does the same and printed a platform warning in the run above. Do not put that file on a public host. The generator is a lab convenience when you cannot install apache2-utils for a throwaway directory. Production directory protection belongs on the server that will read the file: htpasswd -c -B -b file user 'long-password', then -B -b without -c for extra users.
Batch mode (-b) puts the password on the command line. That is how the examples above were captured. On a shared Unix host the password is visible in ps. Prefer being prompted (omit -b) when the password is real. -c overwrites an existing file; the second user is added with htpasswd -B -b file staging … without -c. Deleting staging used -D. Verifying used -v / -vb.
Where the file lives, and what .htaccess still needs
Keep the password file outside the document root so a misconfigured directory listing cannot serve it. Point AuthUserFile at that absolute path. In the same directory (or vhost) you still need AuthType Basic, AuthName (the realm string the browser shows), and Require valid-user. FlashKit’s .htaccess generator drafts HTTPS and www redirects; it does not emit those Auth* lines. Copy them from Apache’s docs or from the folder-protection guide.
HTTPS should wrap Basic auth. Basic sends Base64 of user:password, which is not encryption. A password generator on this site can mint the secret; hash it with -B on the server. Do not reuse the throwaway strings from this article. They were typed on a command line to capture hashes, and they are now public.
If you only needed a {SHA} line for a local Apache that still accepts SHA, the generator will produce it in the tab. Close the tab on a shared computer. For bcrypt, stay on the CLI examples. That split is the whole point of this page: the command that search results for “htpasswd bcrypt” are looking for, plus an honest description of the browser tool.