Use Apache htpasswd to generate encrypted password files and use. htaccess to control Directory Access

Source: Internet
Author: User
Tags crypt md5 md5 encryption

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.