.htpasswd
is a flat-file used to store usernames and password. This file is generally used by the web server software like Apache, Nginx, etc. in order to verify the users via HTTP basic authentication.
What Are .htpasswd File Contents?
.htpasswd is a flat or text file that contains ASCII text. .htpaswd file structures are very simple where every line stores a username and related passwords. The user name and password are delimited with a colon sign. Also, the password is stored in an encrypted way, not a clear text format in order to make the password secure. Below we can see that there are 3 lines where users ismail, ahmet, ali are configured with their encrypted password.
ismail:$apr1$/5EzxSg3$SXVemrqNIb/TrKvJv4Z5r0
ahmet:$apr1$cEKbD/Wa$M012WG8Txqp/dhso8.znk0
ali:$apr1$o/t1Efly$E7798GsGjMWoNUpqmG4l60
How To Create .httpaswd File?
The .htpasswd
file can be created by using htpasswd
command or the touch
command or a text editor. But the most appropriate way is using the httpasswd command. Also the .htpasswd file content can be edited by using the htpasswd command too. Below we will create the .htpasswd file by using the htpasswd command where we will provide the file name with the -c
option.
$ htpasswd -c .htpasswd ismail

Or for the .htpasswd file we can specify the complete path or full path like below.
$ htpasswd -c /var/www/mysite/.htpasswd ismail
Alternatively, we can use the touch command where the created .htpasswd file will be an empty file with just its name.
$ touch .htpasswd
Another alternative to create .htpasswd file is used a command line or GUI text editor. As an example we will use the nano text editor but alternatively the text editors like vi, vim, KWrite can be used.
$ nano .htpasswd
Configure .htpasswd File
As .htpasswd file is used for Apache and related web server software to create user authentication we should configures the web server to use the .htpasswd file. Below we will enable the HTTP basic authentication by specifying the .htpasswd file for username and password.
AuthUserFile /var/www/mysite/.htpasswd
AuthType Basic
AuthName "Poftut HTTP Authentication"
Require valid-user