htpasswd is an Apache gadget that can be found under the Apache installation directory bin.
Usage:
htpasswd [-CMDPSD] passwordfile username
htpasswd-b[cmdpsd] passwordfile username password
Htpasswd-n[mdps] username
Htpasswd-nb[mdps] Username password -C Create a new encrypted password file -n Do not update the file, display the results -M use MD5 encryption
password -D with crypt encryption password (default)-
p unencrypted password-
s using SHA encryption password-
b Enter the password directly at the command line, not the prompt and then enter the password-
d Delete the user
in Windows, NetWare and TPF system, '-M ' is the default password encryption method.
on all other systems, '-p ' may not be available.
1. Generate an encrypted password file
Htpasswd-c. Pass Fdipzone
New password:
re-type new password:
Adding password for user Fdipzone
This generates a file that uses the Crypt encryption password
The following command can generate a file with MD5 encryption password, the role of b parameter is to enter the password directly on the command line, so that you do not need to wait for the password to enter.
HTPASSWD-CMB. Pass Fdipzone 123456
Adding password for user Fdipzone
2. Change the password
htpasswd. Pass Fdipzone
New password:
re-type new password:
Updating password for user Fdipzone
3. Add Users
htpasswd. Pass Guest
new password:
re-type new password:
Adding password for user Guest
4. Delete a user
Htpasswd-d. Pass Guest
Deleting password for user Guest
If you use the P parameter and do not encrypt the password, the system will prompt for warning, so it is best not to use the P parameter for security.
Htpasswd-cp. Pass Fdipzone
warning:storing passwords as plain text might just not work on this platform.
. htaccess call encrypted password file Control access rights
First allowoverride needs to be set to authconfig or all
Then add in the directory where you need to control access. htaccess
The. htaccess content is as follows
AuthType "Basic"
authname "Password Required" #提示文字
authuserfile "/home/fdipzone/sites/pass/.pass" #加密密码的文件
Require Valid-user
When you access files in this directory, the input box that asks for a user name and password pops up. Enter the correct user name and password to access it normally.
tips: for security, encrypted password files should not be placed on the online path that the user can access.