LoginSignup
0
0

More than 1 year has passed since last update.

.htpasswdを、アカウントデータベースから自動作成しよう!

Last updated at Posted at 2021-07-22

目次

1.僕のパソコン環境
2.アカウントデータファイル
3.シェルスクリプト

1. 僕のパソコン環境

  • OS: Ubuntu 20.04.2 LTS

2. アカウントデータファイル

次のようなアカウントデータベースaccount.txt があったとしよう。
簡単のために、(ID)+(半角スペース)+(パスワード)なるフォーマットとする。

account.txt
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10

3. シェルスクリプト

お次は、シェルスクリプトを書こう。.htpasswd を作りたいディレクトリに行き、ターミナルで下記のように書く。

ターミナル
touch .htpasswd
while read line
> do htpasswd -b ./.htpasswd ${line}
> done < account.txt

これで、お望みの「.htpasswd」ができているはず!
一行でもイケる。

ターミナル
touch .htpasswd; while read line; do htpasswd -b ./.htpasswd ${line}; done < account.txt
0
0
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
0
0