how to : Password protect directory with .htaccess and .htpasswd



If you have some files to share among friends in your web server, you can use .htaccess to password protect your directory. To enable this password protect directory feature without any web control panel (ex: CPanel, Ensim, DirectAdmin or etc) is a bit troublesome. No worry, the tutorial below will teach you how to password protect directory using shell or CPanel.

To password protect your website folder with shell command:-

- Create a file name .htaccess in the folder that you want to password protect with the content below:-

AuthName “Password Protect Directory”
AuthType Basic
AuthUserFile /home/username/.htpasswd

Require valid-user

- In shell type:-

htpasswd -c /home/username/.htpasswd your_desire_username
You will be prompt for a new password.
- Once you enter your password, file with name .htpasswd will be created at /home/username directory and now your website folder has been password protected
- Open your browser and try to access your password protected folder. It should now ask you to login now.

To password protect directory with CPanel Hosting Control Panel:-

Login into your CPanel and click on Password Protect Directories
Once you click on Password Protect Directories, you will see a list of directories
Click on the directory that you wish to password protect
Fill in a Username and Password at the bottom of the page, and click Add / modify authorized user
Once user created successfully, just click “Go Back”
Now, Check the Directory requires a password to access via the web
Fill in Protected Resource Name, actually this is just the message that will show in the login window
then, Highlight the user you just created from the Active Users list and click on Save button below the Protected Resource Name
You are Done! The directory you just select has been protected by password.
To ensure you directory has been password protected, launch you browser and visit the folder, if browser prompt you to login, your directory has been protected by password!

Post to Twitter

Tags: , , , , ,

Subscribe to RSS via Email:

Subscribe with Updated Linux and get updates frequently in your inbox

One Response to how to : Password protect directory with .htaccess and .htpasswd

Trackbacks/Pingbacks


    Warning: call_user_func(theme_list_pings) [function.call-user-func]: First argument is expected to be a valid callback in /home/updatedlinux/updatedlinux/wp-includes/comment-template.php on line 1334

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>