zvvgna
Last Updated: May 07, 2017
·
64.92K
· boris

Create htpasswd file for nginx (without apache)

If you're like me, and use Nginx instead of Apache, you could eventually face this problem: Create an htpasswd file (for htaccess "authentication").

To create your file, without installing Apache, just run:

$ printf "USER:$(openssl passwd -crypt PASSWORD)\n" >> .htpasswd

Replace USER and PASSWORD for your user and password :)

2 Responses
Add your response

13764

Hello,

The crypt() function used for this effectively ignores characters beyond 8; you'll see this noted in Apache's documentation as well:
http://httpd.apache.org/docs/2.2/misc/password_encryptions.html

More securely:
$ printf "${username}:`openssl passwd -apr1`\n" >> .htpasswd

This also reads the password from STDIN via openssl, so it doesn't leave traces in shell history.

over 1 year ago ·
14143

openssl pssswd -apr1 option is not available on my system. Is there some requirement needed for this? I did a yum install httpd-tools earlier, but this did not show up.

over 1 year ago ·