[Linux] Implementing user authentication using htaccess file


Writing time : 2015-09-18 22:41:50

Implementing user authentication using htaccess file

Add the following to .htaccess for user authentication.
Note that the .htaccess file must be encoded in ANSI.
If you use other file encoding such as UTF-8, it will not work properly.

AuthUserFile /home/mysite/.htpasswd  
AuthName "my site name"  
AuthGroupFile /dev/null  
AuthType Basic  

AuthUserFile is the path of a file in which authenticated user information is stored.
AuthName Set the text to be displayed in the user authentication information window.

If you have added the .htaccess file, enter the following command to add user information and password.

$ htpasswd -c .htpasswd admin  
New password:  
Re-type new password:  

The htpasswd command creates a file used for authentication.
The -c option creates a file if it does not exist.
.htpasswd is the file name and must be created in the AuthUserFile path entered in .htaccess.
admin is the account to be added.

Add a user and enter the password when New password: appears, and enter the password again when Re-type new password: appears.

If you use the cat command, you can see that the user information has been added to the .htpasswd file.

$ cat .htpasswd  
admin:PsdE3s8s7wRxw  

When adding a second user, enter the command without the -c option.

$ htpasswd .htpasswd webmaster  
New password:  
Re-type new password:  

When the setting is completed and the folder is accessed, the "Authentication required" window is exposed, and access is possible only after authentication with the set account information.

Reference URL


https://www.linux.co.kr/home2/board/subbs/board.php?bo$ITALICWORDtable=lecture&wr$ITALICWORDid=221

Previous post

Next post

Other posts in the category