Introduction.
By placing .htaccess and .htpasswd files in the public area of web content(/home/<UID>/wwws), you can configure settings such as redirects, access restrictions, and the display of custom error pages for each directory.
While useful, you should be careful to set permissions on these files.
Please be careful not to grant more permissions than necessary to prevent others from abusing them.
Note that files such as .htpasswd_Backup, for example, can also be viewed by third parties, so you must manage the permissions including such files.
The following is a description of how to set permissions using Linux command operations.
(On Windows, permissions can be changed by WinSCP or other means, but we will not explain that here.)
How to find the target file.
If you have already installed files such as .htaccess or .htpasswd, you can use the following command to find the path where they are located.
$ cd ~/wwws $ pwd $ find . -name ".ht*" -type f
For example, if the relevant file is located in the /home/testuser123/wwws/TEST directory, the following results will be returned.
[ Example ] * Change of current directory $ cd ~/wwws $ pwd /home/testuser123/wwws * File Search $ find . -name ".ht*" -type f ./TEST/.htpasswd ./TEST/.htaccess
Permission change operation
Use the Linux chmod command to set permissions that satisfy the following conditions.
- Grant read and write permissions to the file owner.
- No permissions are granted to the group.
- Grant only read permission to other users. (System-required setting)
$ cd ~/wwws $ pwd $ chmod 0604 ./<PathToHtFile>/.htpasswd $ chmod 0604 ./<PathToHtFile>/.htaccess * Multiple files can also be specified together in a chmod command. e.g.) chmod 0604 ./<PathToHtFile>/.htpasswd ./<PathToHtFile>/.htaccess
The following is the display when a change permission operation is performed on a file in the /home/testuser123/wwws/TEST/ directory.
[ Example ] * Change of current directory $ cd ~/wwws $ pwd /home/testuser123/wwws * Before $ ls -l ./TEST/.ht* -rwxr-xr-x 1 testuser123 17 3月 2 16:27 ./TEST/.htaccess -rwxr-xr-x 1 testuser123 13 3月 2 10:22 ./TEST/.htpasswd * Change operation $ chmod 0604 ./TEST/.htpasswd $ chmod 0604 ./TEST/.htaccess * After $ ls -l ./TEST/.ht* -rw----r-- 1 testuser123 17 3月 2 16:27 ./TEST/.htaccess -rw----r-- 1 testuser123 13 3月 2 10:22 ./TEST/.htpasswd
The change is complete when the item indicating the permission setting status is “-rw—-r–“.