There are times when we need to protect our entire website or some directories on the website itself. There are plenty of tools out there to help you make it work, but there’s a pretty cool baked in solution from the Apache webserver with little configuration needed.
To do this, go to the directory or the root of your preferred location and put run the command:
sudo htpasswd -c .htpasswd HardeningUser
.htpasswd will be generated to where the command is run and
HardeningUser is the username asked when users access that directory.
The system then pops up asking for the password and the password confirmation inputs. You need to provide whatever password you want there, but remember to take note as the system will encrypt that phrase for security reasons.
Enter the following configuration to the .htaccess file which is also located in that directory:
AuthName "restricted area"
/home/somename/web/domainname.com/public_html/.htpasswd is the path to the