Create a password file
htpasswd -c /path/to/passwd/file admin
To change the password for an existing user
htpasswd /path/to/passwd/file USER_HERE
You can use -b option to specify the password as a command line option, this is useful for adding or updating users non-interactively.
htpasswd -b -c /path/to/passwd/file USER_HERE PASSWORD_HERE
To limit access, add the following to the Apache virtual host entry.
<Directory "/var/www/html">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /path/to/passwd/file
Require valid-user
</Direcory>
Leave a Reply