In order to do this, you will need
Unix shell access (webhotel Medium or larger). Follow these steps: (Do not include the quote signs around commands when running them)
- Login to your website with SSH, with a program like PuTTY or SecureCRT (Windows), Terminal (MacOS).
- Create an empty file named .htpasswd, do this by executing the command "
touch .htpasswd
"
You now need to find the path of your website, you can do this by executing the command "echo $HOME
", which returns the path to your home folder. You can also find this via the webhotel's control panel, by viewing "Web hosting available via" or disk usage.
Substitute this for /home/1/y/youruser/
in the following examples.
Next you run the command htpasswd -csb /home/1/y/youruser/.htpasswd username password
Note that this command overwrites the file .htpasswd if it already exists!
To add another username and password, enter this command:
htpasswd -sb /home/1/y/youruser/.htpasswd username password
Create a file named .htaccess on your local computer and insert this information, replace //home/1/y/youruser/.htpasswd
with the path to your .htpasswd.
<Limit GET POST>
Order deny,allow
AuthType Basic
AuthUserFile /home/1/y/youruser/.htpasswd
AuthName "Password protected area"
Require valid-user
</Limit>
- Upload .htaccess to your webspace, and place it in the folder that needs password protection. You can copy the same .htaccess to multiple folders.
For security reasons, it is important that the name of the password file is ".htpasswd", and that it is located, if possible, in a different directory than the website. The content of files named .htaccess and .htpasswd are not displayed via WWW unless you override this in .htaccess.
For more info about password protection under Apache, see here: