Skip to content
gohacks.dev
DevOps

.htpasswd Generator

Generate an .htpasswd line with Apache's apr1 MD5 or {SHA} hash for Nginx auth_basic or Apache, with the server config to use it.

Free · No sign-up · Your inputs stay in your browser

Input

Generate an .htpasswd entry

Output

htpasswd line

.htpasswd

admin:…

Nginx

auth_basic "Restricted"; auth_basic_user_file /etc/nginx/.htpasswd;

Both Apache and Nginx (auth_basic_user_file) read apr1 and {SHA}. Neither is a strong hash; bcrypt is, and htpasswd -B writes it, but Nginx only reads bcrypt where the system crypt() supports it. Basic auth sends the password with every request, so only use it over HTTPS.

Runs in this browser. Nothing you paste is sent to a server.

Protecting a staging site

Basic authentication is a quick lock for staging environments and admin tools. In Nginx, ngx_http_auth_basic_module reads the file named by auth_basic_user_file; in Apache, AuthUserFile. Keep the file outside the document root.

The hashes

apr1 is MD5 iterated 1,000 times with a salt; {SHA} is a single unsalted SHA-1. Both are fast by modern standards, so use a long random password. htpasswd -B from apache2-utils writes bcrypt, which Apache always understands; Nginx reads it only where the system's crypt() library supports bcrypt, so test a login before relying on it.

Over HTTPS only

Basic auth sends the password, Base64-encoded, with every request. Without TLS anyone on the network reads it.

Share

Frequently asked questions

How do I create .htpasswd without Apache installed?
Generate the line here, or with openssl passwd -apr1, and write it to the file. Each line is user:hash.
Why does Nginx return 500 instead of asking for a password?
Nginx cannot read the file: check the path and that the nginx user has read permission. The error log names the problem.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools