2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Apache Digest認証の設定とユーザー登録・削除を実施してみた

Last updated at Posted at 2023-09-17

はじめに

Apache Digest認証の設定とユーザー登録・削除を実施してみました。

以下の記事を参考にしました。
https://qiita.com/miyuki_samitani/items/ccf9217a058019ca8d59
https://atmarkit.itmedia.co.jp/flinux/rensai/linuxtips/699apachedigest.html
https://www.javadrive.jp/apache/allow/index9.html#section4

設定手順

# vi /etc/httpd/conf/httpd.conf

以下の行を追加しました。

   130  # Further relax access to the default document root:
   131  <Directory "/var/www/html">
   132      AuthType Digest
   133      AuthName "Digest Auth"
   134      AuthUserFile "/etc/httpd/conf/.digestpass"
   135      Require valid-user
   136  </Directory>

Digest test1ユーザー登録した

htdigest [-c] パスワードファイル レルム ユーザー名
#  htdigest -c /etc/httpd/conf/.digestpass "Digest Auth" test1
Adding password for test1 in realm Digest Auth.
New password: <パスワード設定>
Re-type new password: <再度パスワード設定>

Digest test2ユーザーを登録した

-cオプションは新規にパスワードファイルを作成するため
ユーザー追加する際は-cオプションは不要です。

# htdigest /etc/httpd/conf/.digestpass "Digest Auth" test2
Adding user test2 in realm Digest Auth
New password: <パスワード設定>
Re-type new password: <パスワード設定>
[root@localhost conf]#

パスワードファイルの中身を確認してみた

2つのユーザーがパスワードファイルに登録されていることを確認した

# cat /etc/httpd/conf/.digestpass
test1:Digest Auth:60d5cda3e4411ac0226f838a6cf6be4c
test2:Digest Auth:21b5fbaf7785f1f60f55850aaae62047

apacheの文法チェックした

httpd -t

apacheサービスを再起動した

systemctl restart httpd

ブラウザでログイン確認した

image.png
image.png

Digest test1ユーザーを削除しました

ユーザー削除後はapacheの再起動は不要です。

# vi /etc/httpd/conf/.digestpass

変更前

test1:Digest Auth:60d5cda3e4411ac0226f838a6cf6be4c ←削除
test2:Digest Auth:21b5fbaf7785f1f60f55850aaae62047 
test3:Digest Auth:e08259e6350386250a31d98c8dbb376b

変更後

test2:Digest Auth:21b5fbaf7785f1f60f55850aaae62047
test3:Digest Auth:e08259e6350386250a31d98c8dbb376b

ブラウザで削除したtest1ユーザーでログインを試してみた

image.png

test1ユーザーでログイン出来ませんでした。

apacheのアクセスログを確認した

アクセスログを見ると401でUnauthorizedになりました。
参考にしたサイト
https://ipeinc.jp/media/401-error/

# tail -n 1 /etc/httpd/logs/access_log
192.168.0.24 - test1 [17/Sep/2023:21:06:03 +0900] "GET /index.html HTTP/1.1" 401 381 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"

まとめ

ダイジェスト認証をハンズオンする大事さを改めて感じました。
本番環境ではダイジェスト登録時に誤ってhtdigest -c パスワードファイル
で新規にユーザー登録して既存のユーザー情報を誤って消してしまうリスクがあります。
コマンドのオプションの意味を普段から理解して作業する習慣を付けた方が良いです。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?