Set Apache Web server password Authentication

Source: Internet
Author: User

Straight to the theme!!!

1. You need to modify the HTTPD master profile, which is installed by default at/etc/httpd/conf/httpd.conf

2.VI edit this file

3. Need to modify a few lines of code

Find the contents of <directory "/var/www/html" > and </Directory>, modify the information

A. Change allowoverride none to allowoverride authconfig first

B. Adding AuthType Basic

C. Add AuthName "My private website ..."

D. Adding user files to allow access AuthUserFile "/ETC/HTTPD/CONF/HTPASSWD"

E. Add the user who is allowed to access require users Tom Jerry (change to require valid-user if you want htpasswd inside users to be accessible)

4. Create a password file

# htpasswd-c-M/ETC/HTTPD/CONF/HTPASSWD Tom

Enter Tom's password as prompted, enter two times, and then create a Jerry user

# htpasswd-m/ETC/HTTPD/CONF/HTPASSWD Jerry

Note: Here must no longer use the-C, because the-C means to create a password file, only if there is no password file is needed, the password file will be deleted directly from the original, plus-m indicates that the added user has been MD5 encrypted way

If you delete a user then use the-D option, such as # htpasswd-d/etc/httpd/conf/htpasswd Tom deletes the Tom user

5. Restart the Web service

#service httpd Restart


-----------------------------------------------------------------------------above is to create a user password, that is, to restrict certain users, In fact, HTTPD also support the restrictions on the group, which is explained below--------------------


If you need to operate on a group, do this:

1. You need to modify the HTTPD master profile, which is installed by default at/etc/httpd/conf/httpd.conf

2.VI edit this file

3. Need to modify a few lines of code

Find the contents of <directory "/var/www/html" > and </Directory>, modify the information

A. Change allowoverride none to allowoverride authconfig first

B. Adding AuthType Basic

C. Add AuthName "My private website ..."

D. Adding user files to allow access AuthUserFile "/ETC/HTTPD/CONF/HTPASSWD"

E. Adding a group file that is allowed access AuthGroupFile "/etc/httpd/conf/htgroup"

F. Adding a group to allow access require group Mygroup1 mygroup2

4. Create a password file

# htpasswd-c-M/ETC/HTTPD/CONF/HTPASSWD Tom

Enter Tom's password as prompted, enter two times, and then create a Jerry user

# htpasswd-m/ETC/HTTPD/CONF/HTPASSWD Jerry

Note: Here must no longer use-C, because the-C means to create a password file, only if there is no password file, the password file will be deleted directly from the original

5. Create a group file

#vim/etc/httpd/conf/htgroup

(Add content to the file)

Mygroup1:tom Jerry

Mygroup2:tom

Save the exit, note that the user here must be in the password file exists in the user.

6. Restart the Web service

#service httpd Restart

Now you can see that you need to enter a verification password.

Set Apache Web server password Authentication

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.