<pre>ユーザーディレクトリ表示設定
root@falcon21:~# vi /etc/httpd/conf.d/userdir.conf
#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid. This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
#
<IfModule mod_userdir.c>
#
# UserDir is disabled by default since it can confirm the presence
# of a username on the system (depending on home directory
# permissions).
#
#UserDir disabled
#
# To enable requests to /~user/ to serve the user's public_html
# directory, remove the "UserDir disabled" line above, and uncomment
# the following line instead:
#
UserDir public_html
AliasMatch ^/kazuya(.*) /home/xxxxxx/public_html/$1
AliasMatch ^/hayato(.*) /home/yyyyyy/public_html/$1
AliasMatch ^/anjii(.*) /home/zzzzzz/public_html/$1
AliasMatch ^/userdir/([^/]+)/(.*) /home/$1/public_html/$2
</IfModule>
#
# Control access to UserDir directories. The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory "/home/*/public_html">
#AllowOverride FileInfo AuthConfig Limit Indexes
#Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
AllowOverride All
Options +ExecCGI
AddHandler cgi-script .pl .cgi
</Directory>
ユーザーディレクトリを作成
ユーザーディレクトリ一括作成スクリプト作成
[root@falcon21 ~]# vi userdirmake
#!/bin/bash
for user in `ls /home`
do
id $user > /dev/null 2>&1
if [ $? -eq 0 ] && [ ! -d /home/$user/public_html ]; then
mkdir -p /home/$user/public_html
chown $user. /home/$user/public_html
chmod 711 /home/$user
echo $user
fi
done
----------------------
ユーザーディレクトリ一括作成スクリプト実行
[root@falcon21 ~]# bash userdirmake
確認
[root@falcon21 ~]# ll /home
合計 0
drwx--x--x. 4 xxxxxx xxxxxx 97 11月 12 15:13 xxxxxx
drwx--x--x. 5 yyyyyy yyyyyy 133 11月 12 15:13 yyyyyy
drwx--x--x. 4 zzzzzz zzzzzz 97 11月 12 15:13 zzzzzz
----------------------
ユーザーディレクトリ一括作成スクリプト削除
[root@falcon21 ~]# rm -f userdirmake
新規ユーザー追加時にユーザーディレクトリ(~/public_htmlディレクトリ)が自動で作成されるようにする
ユーザー追加時に~/public_htmlディレクトリが自動で作成されるようにする
[root@falcon21 ~]# mkdir /etc/skel/public_html
ユーザーウェブテストページ作成
/home/xxxxxx/public_html に、テストページ作成・表示確認
xxxxxx@falcon21:~$vi public_html/index.html
<html>
<body>
<h1 style="width: 100%; font-size: 40px; text-align: center;">
hayato_Dir Test Page
</h1>
</body>
</html>
ウェブページ表示確認
http://192.168.10.3/xxxxxx/
xxxxxx_Dir Test Page
サーバーデスクトップ・firefox で表示
***********************************************************************
アクセス制限ページ設定 htpasswd
htpasswd 設定
root@falcon21:~# htpasswd -c /etc/httpd/conf/.htpasswd xxxxxx
New password:
Re-type new password:
Adding password for user xxxxxx
htpasswd にユーザーを追加 設定 -c オプションを外す
# htpasswd /etc/httpd/conf/.htpasswd ユーザー名
root@falcon21:~# htpasswd /etc/httpd/conf/.htpasswd yyyyyyy
New password:
Re-type new password:
Adding password for user yyyyyy
root@falcon21:~# htpasswd /etc/httpd/conf/.htpasswd zzzzzz
New password:
Re-type new password:
Adding password for user zzzzzz
確認
[root@falcon21 ~]# cat /etc/httpd/conf/.htpasswd
----------------
.htaccess ファイルの作成
/home /user ディレクトリーごとに作成して、必要時のみそのディレクトリーにコピーして、利用
[root@falcon21 ~]# su - xxxxxx
最終ログイン: 2025/11/12 (水) 16:45:20 JST 端末:pts/1
[xxxxxx@falcon21 ~]$ vi .htaccess
AuthUserFile /etc/httpd/conf/.htpasswd
AuthGroupFile /dev/null
AuthName "secret page"
AuthType Basic
require valid-user
[xxxxxx@falcon21 ~]$ cp -f .htaccess public_html/
----------------
アクセス制限ページ表示確認
http://192.168.10.3/xxxxxx/
----------------
アクセス制限用ページを shtmlで作成
[root@falcon21 ~]# su - xxxxxx
最終ログイン: 2025/11/12 (水) 16:33:14 JST 端末:pts/1
[xxxxxx@falcon21 ~]$ vi public_html/index.shtml
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>テスト</title>
<body>
<p>.htaccessにアクセス制限ページ</p>
このページは、index.shtml 使用 <!--#echo var="DOCUMENT_NAME" -->
</body>
</html>
~
----------------
同じディレクトリーに、index.html がある場合は、こちらが優先される。
.htaccessファイルを /home/yyyyyy/public_html にコピーして、テスト
[root@falcon21 ~]# cp /home/.htaccess /home/yyyyyy/public_html/
/home/yyyyyy/public_html にテストページ作成
[root@falcon21 ~]# echo test >> /home/yyyyyy/public_html/index.html
192.168.10.3/yyyyyy/ ・・・そのまま表示、パスワード要求が出ない。
.htaccessが有効にならない。
</pre>