提供:あわWiki
移動先: 案内検索

Webページパスワード制限(htpasswd)(CentOS7)

メインページ > CentOS 7 で自宅サーバー構築  > Webページパスワード制限(htpasswd)(CentOS7)

※Webサーバーは.htaccessを許可設定済みとする。

.htpasswdファイル作成

.htpasswdファイルを新規作成する場合

[root@host3 ~]# htpasswd -b -c -m /etc/httpd/conf/.htpasswd sudachi sudachipassword
← .htpasswdを作成してユーザーsudachiを登録する Adding password for user sudachi

既存の.htpasswdファイルへユーザーを追加する場合

[root@host3 ~]# htpasswd -b -m /etc/httpd/conf/.htpasswd sudachi sudachipassword
← 既存の.htpasswdへユーザー sudachiを登録する
Adding password for user sudachi

ユーザー登録確認

[root@host3 ~]# cat /etc/httpd/conf/.htpasswd ← ユーザー登録確認
sudachi:syipeg7crzq9c

Webページパスワード制限

.htaccessファイル作成

.htpasswdに登録してある全てのユーザー名で認証できるようにする場合

[root@host3 ~]# vi /var/www/html/sudachi/.htaccess ← テスト用ディレクトリに.htaccess作成
SSLRequireSSL
AuthUserFile /etc/httpd/conf/.htpasswd
AuthGroupFile /dev/null
AuthName "secret page"
AuthType Basic
require valid-user

.htaccessファイル作成

.htpasswdに登録してある特定のユーザー名(ここでは、認証を許可するユーザー名をsudachiとする)でのみ認証できるようにする場合

[root@host3 ~]# vi /var/www/html/sudachi/.htaccess ← テスト用ディレクトリに.htaccess作成
SSLRequireSSL
AuthUserFile /etc/httpd/conf/.htpasswd
AuthGroupFile /dev/null
AuthName "secret page"
AuthType Basic
require user sudachi ← 認証を許可するユーザー名を指定