apache:basic_authentication
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
apache:basic_authentication [2016/10/13 22:35] – peter | apache:basic_authentication [2023/07/17 08:45] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Apache - Basic Authentication ====== | ||
- | ===== Configure Apache to allow .htaccess authentication. ===== | ||
- | |||
- | By default Apache does not allow the use of .htaccess files. | ||
- | |||
- | You can do this by editing the Apache config file: | ||
- | |||
- | <code bash> | ||
- | sudo vi / | ||
- | </ | ||
- | |||
- | Find the section that begins with **< | ||
- | |||
- | <file apache / | ||
- | AllowOverride AuthConfig | ||
- | </ | ||
- | |||
- | Save and close the file. | ||
- | |||
- | |||
- | ===== Create a password file with htpasswd ===== | ||
- | |||
- | The **htpasswd** command is used to create and update the files used to store usernames and password for basic authentication of Apache users. | ||
- | |||
- | Let's begin by creating a .htpasswd file for user1. | ||
- | |||
- | <code bash> | ||
- | sudo htpasswd -c / | ||
- | </ | ||
- | |||
- | You will be asked to supply and confirm a password for user1. | ||
- | |||
- | **NOTE**: Only use **-c** the first time you create the file. Do not use **-c** when you add a user in the future. | ||
- | |||
- | Let's create another user named user2: | ||
- | |||
- | <code bash> | ||
- | sudo htpasswd | ||
- | </ | ||
- | |||
- | After creating user2, you can see the username and the encrypted password for each record: | ||
- | |||
- | <code bash> | ||
- | sudo cat / | ||
- | </ | ||
- | |||
- | The output will look something like this: | ||
- | |||
- | < | ||
- | user1: | ||
- | user2: | ||
- | </ | ||
- | |||
- | Now, you need to allow the apache user to read the .htpasswd file. | ||
- | |||
- | <code bash> | ||
- | sudo chown apache: | ||
- | sudo chmod 0660 / | ||
- | </ | ||
- | |||
- | |||
- | ===== Configure Apache password authentication ===== | ||
- | |||
- | Now you need to create a .htaccess file in the web directory you wish to restrict. | ||
- | |||
- | For this example, we will create the .htaccess file in the / | ||
- | |||
- | <code bash> | ||
- | sudo vi / | ||
- | </ | ||
- | |||
- | Add the following content: | ||
- | |||
- | <file apache / | ||
- | AuthType Basic | ||
- | AuthName " | ||
- | AuthUserFile / | ||
- | Require valid-user | ||
- | </ | ||
- | |||
- | Save and close the file, then restart Apache to make these changes take effect. | ||
- | |||
- | <code bash> | ||
- | sudo apachectl restart | ||
- | </ | ||
- | |||
- | |||
- | ===== Testing password authentication ===== | ||
- | |||
- | After everything has been set up, it's time to test your Apache server. | ||
- | |||
- | From your desktop computer, try to access your restricted content in a web browser by visiting your URL or static IP address. | ||
- | |||
- | You will be prompted with a username and password to access the website. | ||
- | |||
- | If you enter the correct credentials, | ||
- | |||
- | If you enter the wrong credentials or hit " | ||
- | |||
- | Your website is now secure with password authentication. | ||
- | |||
- | |||
- | |||
- | ===== References ===== | ||
- | |||
- | http:// |
apache/basic_authentication.1476398108.txt.gz · Last modified: 2020/07/15 09:30 (external edit)