Differences
This shows you the differences between two versions of the page.
| password_protect [2022/02/05 14:13] – created norman | password_protect [2022/02/05 14:23] (current) – norman | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| Run pwd to confirm the full file path to this directory. You'll need this full path in the next step. | Run pwd to confirm the full file path to this directory. You'll need this full path in the next step. | ||
| - | <code> | + | <cli> |
| - | / | + | / |
| Create an .htpasswd file by running the following command in the directory you wish to password protect. This uses the htpasswd utility and the full path to the directory. For example, if the username you're creating to log in is user1, run the following: | Create an .htpasswd file by running the following command in the directory you wish to password protect. This uses the htpasswd utility and the full path to the directory. For example, if the username you're creating to log in is user1, run the following: | ||
| - | <code> | + | <cli> |
| - | Enter a password for the new user named user1. The code in your .htpasswd file then displays the encrypted password like this: | + | Enter a password for the new user named user1. The cli in your .htpasswd file then displays the encrypted password like this: |
| - | <code>nano ./ | + | <cli>nano ./ |
| - | user1: | + | user1: |
| Run it again (without the -c option) for any other users you wish to allow access to your directory. | Run it again (without the -c option) for any other users you wish to allow access to your directory. | ||
| Line 26: | Line 26: | ||
| Confirm the permissions are set to 644 by running the following command. | Confirm the permissions are set to 644 by running the following command. | ||
| - | <code> | + | <cli> |
| ===== Step 2 — Create the .htaccess file ===== | ===== Step 2 — Create the .htaccess file ===== | ||
| Line 34: | Line 34: | ||
| - | <code> | + | <cli> |
| ====== | ====== | ||
| - | Code examples to add to the .htaccess file | + | cli examples to add to the .htaccess file |
| Protect an entire website | Protect an entire website | ||
| This example password protects an entire website by placing the files in the site's main web directory. ====== | This example password protects an entire website by placing the files in the site's main web directory. ====== | ||
| Line 43: | Line 43: | ||
| Make sure to change the highlighted lines to your username, domain name, and specific file names. | Make sure to change the highlighted lines to your username, domain name, and specific file names. | ||
| | | ||
| - | <code># | + | <cli># |
| AuthName " | AuthName " | ||
| AuthType Basic | AuthType Basic | ||
| AuthUserFile / | AuthUserFile / | ||
| - | Require valid-user</ | + | Require valid-user</ |
| Protect a single file | Protect a single file | ||
| This example password protects a single file named admin.php: | This example password protects a single file named admin.php: | ||
| - | <code># | + | <cli># |
| <Files admin.php> | <Files admin.php> | ||
| AuthName " | AuthName " | ||
| Line 58: | Line 58: | ||
| AuthUserFile / | AuthUserFile / | ||
| Require valid-user | Require valid-user | ||
| - | </ | + | </ |
| Protect multiple files | Protect multiple files | ||
| This example protects multiple files such as admin.php and staff.php. | This example protects multiple files such as admin.php and staff.php. | ||
| - | <code># | + | <cli># |
| < | < | ||
| AuthName " | AuthName " | ||
| Line 69: | Line 69: | ||
| AuthUserFile / | AuthUserFile / | ||
| Require valid-user | Require valid-user | ||
| - | </ | + | </ |
| Rest can read on https:// | Rest can read on https:// | ||