How Do I Create A Password Protected Directory?
Plesk
- After loggging on to your Plesk control panel you will want to click on the "Home" link on the left-hand menu. When the page loads click on the "Protected Directories" icon under the "Hosting" category.
- Under the "Tools" category click on the "Add New Directory" icon.
- Fill in the "Directory name" with the directory that you want protected. If you have a directory in /httpdocs/mydir, you would enter "/mydir" into the Directory name field
- Check both Non-SSL and SSL for the location, and only click cgi-bin if the directory is in your /cgi-bin directory instead of your /httpdocs directory
- The header text can be anything you want. The user will see this on the password prompt window.
- Then click OK
- The configuration page for the new protected directory will be displayed. Click on the "Add New User" icon.
- Enter the Username and Password into the fields and press OK
- After adding a user you can browse to that protected directory and it should prompt your for the Username and Password.
Shell (Only if you have this enabled for your website)
- SSH in, and login using the adminstrative FTP username and password
- Navigate to the directory you want to password protect.
- Create the .htaccess file, it should contain the following lines:
# Access file
order allow,deny
allow from all
require valid-user
Authname DirectoryName
AuthPAM_Enabled off
Authtype Basic
AuthUserFile /var/www/vhosts/YourDomain/httpdocs/Directory/.htpasswdMake Sure To Replace DirectoryName, YourDomain and Directory as appropriate
- Now you must create the .htpasswd file using the htpasswd tool.
- Type the following command to create the file and add a user:
htpasswd -c .htpasswd username
- You will be prompted for the users' password twice.
- Type the following command to create the file and add a user:
- If you need to add additional users to the file, use the command above without the -c.