Let's suppose you want to protect web pages in your UNIX directory called project to username UserA and password secret. To do that, you need to create 2 files (.htaccess and .htpasswd), and put them in your UNIX directory project.
- Create a text file called .htaccess in directory project that looks like this:
AuthUserFile /home/<login-name>/public_html/<DirectoryName>/.htpasswd
AuthGroupFile /dev/null
AuthName Page Authentication
AuthType Basic
require valid-userRemark: <login-name> = Your UNIX Username
<DirectoryName> = project - In project directory, create the password file .htpasswd using the following UNIX command:In order to do this, you need to use SSH client to connect the UNIX server.
htpasswd -c .htpasswd <UserName>
Remark: <UserName> = UserAThen, type in the password secret twice as instructed.
N.B. It is assumed that .htpasswd does not exist. If you have created one and want to add a second user to .htpasswd file, please try the following command:
htpasswd .htpasswd <UserName2>
Remark: <UserName2> = UserB
Then, type in another password secret2 twice as instructed.
- Now, try to access a web page in directory project -- your browser should demand a username and password, and not give you access to the file unless you enter UserA and secret or enter UserB and secret2 for the username and password respectively.
Note: If you are using a browser that doesn't handle authentication, you will not be able to access the document at all.
Remarks:
- Users should have the basic knowlege of UNIX operating system such as UNIX commands, file structure and security control for the above operations.
- Users can refer to the UNIX Command Quick Reference for basic UNIX command.
How to connect UNIX server using SSH Client:
You can use either following SSH client to connect to the server moon.eduhk.hk
PuTTY is available in all OCIO provided PC. You can invoke PuTTY via WinSCP by clicking Start -> Programs -> WinSCP. Connect to the server then click Commands -> Open in PuTTY from the menu bar.