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 :)
Written by Boris Quiroz
Related protips
2 Responses
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.
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.