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
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/87743/4bdb9d85e4b21bab0a53caed145637e2.png)
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.
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/105717/9dc0f9c6ec932b7dd83a93b738e4f2a1.jpg)
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.