Skip to content

htpasswd Generator

Create the password file for HTTP Basic auth, check a password against a file you already have, and copy the nginx, Apache, Caddy or Traefik config that uses it.

Free · No signupHashed in your browser

htpasswd generator

Hash

$2y$ Salted and deliberately slow. Use this.

Cost

Each step up doubles the work. The server runs one check on every request to the protected path, including each image and script.

Users1 user
  • User 1

Keeps its other users and replaces anyone you add here, as htpasswd does without -c.

# Give each user a password, or generate one.
# The file appears here, one username:hash per line.
  • Basic auth sends the password with every request, encoded but not encrypted. Serve the site over HTTPS. Changes to the file apply on the next request, with no reload.

Prefer your terminal?

sudo htpasswd -c -B -C 10 /etc/nginx/.htpasswd admin

It asks for the password, so it stays out of your shell history. -c creates the file and replaces one that is already there.

Hashed in this tab. Passwords and files never leave this page.

Basic auth is a quick gate, not a strategy

Manage real access across your servers.

CtrlOps gives every teammate their own SSH key on the login they need on each server, so access is granted and removed per person, with credentials encrypted on your own machine.

Explore PermissionsDownload for MacDownload for Windows

Keep it handy

htpasswd hashes,
side by side.

The prefix tells a server how a line was hashed. The htpasswd column is the flag that makes it, and the last two say where each one can be checked.

htpasswd hash algorithms and server support
AlgorithmPrefixhtpasswdSecuritynginxApache
bcrypt$2y$-BStrong. Use this.Through the system crypt(): current distros2.4 and later, every platform
SHA-512 crypt$6$-5Fair. Salted, 5,000 roundsLinuxLinux
apr1$apr1$-mWeak. Iterated MD5YesYes
SHA-1{SHA}-sVery weak. Unsalted1.3.13 and laterYes
cryptnone-dBroken. 8-character limitLinuxLinux

How Basic auth works

One line per user.
Checked on every request.

What is an .htpasswd file?

An .htpasswd file stores the logins for HTTP Basic authentication, one username:hash line per user. nginx and Apache read it to put a password in front of a path, which makes it the quickest way to close off a staging site, a dashboard or an internal tool. The passwords are never stored, only their hashes, and this tool makes those hashes in your browser.

Which hash should you use?

Use bcrypt ($2y$). It is salted and slow by design. Apache has read it since 2.4. nginx hands it to the operating system's crypt(), which reads bcrypt on current Debian, Ubuntu, RHEL 8 and later, Alpine and the official nginx images. On CentOS 7, Amazon Linux 2 or Ubuntu 18.04, a bcrypt line gets a 500 error, so use SHA-512 crypt ($6$) there. apr1 and SHA-1 still work everywhere, but a leaked file gives their passwords up quickly.

Why the bcrypt cost matters more here

A browser sends the password with every request, and neither nginx nor Apache remembers that it already checked it. So a page with thirty images and scripts runs the hash thirty times. Each step up in cost doubles the work. Cost 10 is a sound default; htpasswd itself uses 5 for this reason. The tool times the hash on your device so you can judge it.

Where the file belongs

Keep it outside the web root. Apache refuses to serve files starting with .ht, but nginx has no such rule, so an .htpasswd in the document root can be downloaded. The server reads the file on each request as its worker user, so make it root:www-data with mode 640. Edits apply on the next request, with no reload.

Basic auth needs HTTPS

The browser sends username:password base64-encoded, which anyone on the path can decode. Serve the site over HTTPS. Protecting the whole site also blocks Let's Encrypt renewals, so the generated nginx and Apache config lets /.well-known/acme-challenge/ through. Basic auth guards a URL, not the server behind it.

Control who can reach the server itself

htpasswd FAQ

Basic auth,
explained.

Keep working

Related tools for your next task.

Your privacy preferences. We use product analytics to improve CtrlOps. Google measurement runs without analytics cookies. Live chat stays off until you allow it. Cookie policy