【apache】Basic・Digest認証

  • 投稿者:
  • 投稿カテゴリー:apache

概要

Basic認証だとユーザー名・パスワードが平文で流れる
Digest認証だとユーザー名・パスワードが暗号化されるため多少マシ

Basic認証

## 認証に必要なapacheモジュール読み込み ##
root@hostname:/etc/apache2# a2enmod auth_basic authn_file
Module auth_basic already enabled
Module authn_file already enabled

## サイトの設定変更 ##
root@hostname:/home/shimizu# vi /etc/apache2/sites-enabled/000-default
=以下を追記=
<Location /wp-admin>
        AuthType Basic
        AuthName "secret"
        AuthUserFile /etc/apache2/.htpasswd
        Require valid-user
</Location>
===========

## Digest認証設定ファイル作成 ##
## htpasswd オプション("-c" を付けるとその次の引数で指定されたファイルを新規作成する、つけなければ追加する) パスワードファイル名 ユーザー名
root@hostname:/etc/apache2# htpasswd -c .htpasswd user
New password:
Re-type new password:
Adding password for user user
root@hostname:/etc/apache2# cat .htpasswd
user:$apr1$As7TC2oV$sbI625W54uEVH0woDGHgZ.

## apacheの再起動 ##
root@hostname:/home/shimizu# apache2ctl configtest
Syntax OK 
root@hostname:/etc/apache2# /etc/init.d/apache2 reload
[ ok ] Reloading web server config: apache2.

Digest認証

## 認証に必要なapacheモジュール読み込み ##
root@hostname:/home/shimizu# a2enmod auth_digest authz_owner authz_user authn_file
Enabling module auth_digest.
Enabling module authz_owner.
Module authz_user already enabled
Module authn_file already enabled
To activate the new configuration, you need to run:
  service apache2 restart

## サイトの設定変更 ##
root@hostname:/home/shimizu# vi /etc/apache2/sites-enabled/000-default
=以下を追記=
<Location /wp-admin>
        AuthType Digest
        AuthName "secret"
        AuthUserFile /etc/apache2/.htdigest
        Require valid-user
</Location>
===========

## Digest認証設定ファイル作成 ##
## htdigest オプション("-c" を付けるとその次の引数で指定されたファイルを新規作成する、つけなければ追加する) パスワードファイル名 領域名 ユーザー名
root@hostname:/etc/apache2# htdigest -c .htdigest 'secret' user
Adding password for user in realm secret.
New password:
Re-type new password:
root@hostname:/etc/apache2# cat .htdigest
user:secret:9d5a877dbb653780fd6715e1cd96c61a

## apacheの再起動 ##
root@hostname:/home/shimizu# apache2ctl configtest
Syntax OK 
root@hostname:/etc/apache2# /etc/init.d/apache2 reload
[ ok ] Reloading web server config: apache2.

参考URL

必要なモジュール
http://blog.h2o-feeling.com/?p=249
概要と設定
http://fun4life.jpn.ph/diary/2012/07/18/wordpress-%E3%81%ABdigest-%E8%AA%8D%E8%A8%BC-%E4%BD%BF%E3%81%86/