Password Protected Pages: Htpasswd and Htaccess

Mar 31st, 2008 | By admin | Category: Javascript, Linux

Password protected web pages may have crucial importance for you, if you want to hide some of your pages to public. If you have a configured apache server for this, it’s so easy to do the rest to add a password and a user to protect a page or folder.

Here how it is done:

1. Configuring your htaccess

If you do not have a .htaccess file on your website’s directory, create it. But don’t forget that it is a hidden file, if you are using SSH Secure Shell’s browser, you have to select “View” >> ” Show Hidden Files ” to see whether you have created one, before.

Now, add the following code to your .htaccess file.

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /<fullpath>/
require valid-user

After AuthName field, write a message that will be seen on the authentication screen and don’t forget to add your fullpath after the AuthUserFile field. It is usually something like this: AuthUserFile /home/.servername/www/ .htpasswd

2. Configuring your .htpasswd

.htpasswd is a hidden file that has the encrypted password combinations of your users for authentication. It must be put in a non-public folder, to prevent visitors from viewing this file via a browser. You can put it such as directly above your public HTML folder. Now you understand what it stands for. This htpasswd can be directly created via command line of Linux servers. On the prompt screen of your linux server, type the following command and be sure to run this command above your html folder:

htpasswd -cmd .htpasswd <username>

You’ll be prompted to write your desired password. After that, go to to see if everything is ok. You’ll be asked to login with your username and password.

3. Adding More Users

Adding more users is easy. Just type the following command on the command screen of your server:

htpasswd .htaccess

Type the desired password and that’s all.

  • Share/Save/Bookmark
Tags: , , ,

One comment
Leave a comment »

  1. Nice post, Thanks!

Leave Comment