ディレクトリにユーザ/パスワード認証を設定する(BASIC認証)¶
- 特定のディレクトリ(またはアドレス)にユーザ認証を設定する。
 一般的に、以下のパターンでユーザ名とパスワードを解決することが出来る。- 専用に作成したユーザ名・パスワードファイルによる認証
- 認証サーバ(OpenLDAP)を使用したユーザ名・パスワードによる認証
 
パスワードファイルによる実装例¶
- (/dir 以下に認証を設定する)
- 初回のみユーザファイル・パスワードファイルを作成する。# cd /etc/httpd/conf # htpasswd -c .htpasswd username 
- ユーザファイル・パスワードファイルを追加・更新する。# cd /etc/httpd/conf # htpasswd .htpasswd username 
- confに下記のコードを記入する。<Location "/dir"> AuthName "認証ダイアログのタイトル" AuthType Basic AuthUserFile /etc/httpd/conf/.htpasswd Require valid-user AllowOverride None Order allow,deny Allow from all </Location>
- Apacheをリスタートする。# service httpd restart 
LDAPサーバによる実装例¶
- (/dir 以下に認証を設定する)
- LDAPサーバの構築については省略
- confに下記のコードを記入する。(ユーザ名をuidとして登録している場合)<Location "/dir"> AuthName "認証ダイアログのタイトル" AuthType Basic AuthBasicProvider ldap AuthzLDAPAuthoritative off AuthLDAPURL ldap://192.168.0.xxx/dc=example,dc=com?uid Require valid-user AllowOverride None Order allow,deny Allow from all </Location>
- Apacheをリスタートする。# service httpd restart 
ローカルユーザによる実装例¶
- rootユーザではログインできない。
- パスワード無しのユーザではログインできない。
- 必要モジュールをインストールする。# yum install mod_authnz_external pwauth 
- (/dir 以下に認証を設定する)
- confに下記のコードを記入する。<Location "/dir"> AuthType Basic AuthName "Staff content" AuthBasicProvider external AuthExternal pwauth require valid-user </Location>
- PAM認証設定を変更する。# vi /etc/pam.d/pwauth #------------------------------------------------------------ #%PAM-1.0 #auth include password-auth #account include password-auth auth include system-auth account include system-auth session include system-auth 
- Apacheをリスタートする。# service httpd restart 
¶
¶