How do I password protect my website?
Please note: This support article is a guide for our Linux users only.
The following article explains how to password protect your website. This is done through the use of a .htaccess file and a .htpassword file. Either the entire website or a specific folder can be password protected. The .htaccess file is placed within the folder and links to a .htpasswd file that contains the login and password information. Typically the .htpasswd file is stored the same directory as the .htaccess file.
To password protect your website, please follow these steps:
- Log into your Linux web server via Secure Shell (SSH).
- Change into the directory you wish to password protect.
Note: If you wish to protect your entire website us the following command:
cd /vservers/username/htdocs
- Create a file called .htaccess using the following command:
pico .htaccess
- Enter the following information:
AuthType Basic
AuthName "Please enter your Username and Password"
AuthUserFile /vservers/username/htdocs/.htpasswd
AuthGroupFile /dev/null
Require valid-user
- Press ctrl+o to save the file.
- Press ctrl+x to exit the file.
- Create the .htpasswd file using the following command:
/usr/bin/htpasswd -c /vservers/username/htdocs/.htpasswd username
- Enter the password you wish to use.
- Re-enter the password.
- Grant read access to each file using the following commands:
chmod a+r .htaccess
chmod a+r .htpasswd