zvvgna
Last Updated: May 07, 2017
·
59.09K
· boris
Beer avatar

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 :)

Say Thanks
Respond

2 Responses
Add your response

13764
4bdb9d85e4b21bab0a53caed145637e2

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
9dc0f9c6ec932b7dd83a93b738e4f2a1

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 ·