Member Support ~ Linux Admin User Guide ~ Restricting Access

1. Execute the following command:

$ htpasswd -c /home/username/htusers martin

where:
-c : New file, only use at first time.
/home/username/ : the directory of the password file located.
htusers : the password file, you may choose any name you like.
martin : username

The -c argument tells
htpasswd to create new users file. When you run this command, you will be prompted to enter a password for martin, and confirm it by entering it again. Other users can be added to the existing file in the same way, except that the -c argument is not needed. The same command can also be used to modify the password of an existing user. 

After adding a few users, the
/home/username/htusers file might look like this: 

martin:WrU808BHQai36
jane:iABCQFQs40E8M
art:FAdHN3W753sSU

The first field is the username, and the second field is the encrypted password. 


2. To restrict a directory to any user listed in the users file just created, you should create a
.htaccess file containing the follow text and save in the directory: 

AuthName "restricted stuff"
AuthType Basic
AuthUserFile
/home2/username/htusers

require valid-user

The first directive, AuthName, specifies a realm name for this protection. Once a user has
entered a valid username and password, any other resources within the same realm name can be accessed with the same username and password. This can be used to create two areas which share the same username and password.


Further Information
Using User Authentication
DBM User Authentication

 

Room 1619, Fortune Commercial Building, 362 Sha Tsui Road, Tsuen Wan, N.T.
Tel: (852) 2409-8602    Fax: (852) 2408-8632    E-mail: info@unisite.net