1
0

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 3 years have passed since last update.

OpenSSLでパスワード作成-Ansibleで設定するパスワードについて-

Last updated at Posted at 2021-08-12

Ansibleでパスワードを設定したい

Ansibleでリモートマシンにパスワードを設定したい時、平文で送ってもダメポなので、ここはOpenSSLの力を借りてパスワードを生成して送りつけましょう。

OpenSSLでのパスワード生成方法

OpenSSLではこのようにすればパスワードが生成できるようです。

bash
$ openssl passwd --help
Usage: passwd [options]
Valid options are:
 -help               Display this summary
 -in infile          Read passwords from file
 -noverify           Never verify when reading password from terminal
 -quiet              No warnings
 -table              Format output as table
 -reverse            Switch table columns
 -salt val           Use provided salt
 -stdin              Read passwords from stdin
 -6                  SHA512-based password algorithm
 -5                  SHA256-based password algorithm
 -apr1               MD5-based password algorithm, Apache variant
 -1                  MD5-based password algorithm
 -aixmd5             AIX MD5-based password algorithm
 -crypt              Standard Unix password algorithm (default)
 -rand val           Load the file(s) into the random number generator
 -writerand outfile  Write random data to the specified file

とりあえず強度が強そうな SHA512 で作りましょう。

こんな感じ。

bash
$ openssl passwd -6
Password: 
Verifying - Password: 
$6$dWEZ1Y/sNA3XMwWh$kyDNas6/gsq7Vy5HaAsWHSEQdXmC5JLrdvH7vckv7gKAfOpP4lJTvVuAc略

これでもいいですが、saltで少し遊んでみましょう。
saltの設定方法は

bash
$ openssl passwd -6 -salt=salt 
Password: 
$6$salt$RI5GdyZIyW7xvU0UR7.Y0UCl1tjahnVIePvmc/Aynwm5SFRY0JdwGZYc8p8sOYEsmP0zXjAR略

となっています。
もう少し遊んでみましょう。

ちょっと冒険

毎回、saltの値を替えて遊ぶには

bash
$ openssl passwd -6 -salt=$RANDOM 
Password: 
$6$16043$86yLt7.CVehA7lWR5H5pA543nLz6U4CzEUwikNQmRRSwvIa0dmOW0O9ICEUqKjSwg3iBG/g略
$ openssl passwd -6 -salt=$RANDOM 
Password: 
$6$25764$yybCGULsCXBn4Iq1P1KIrS2MWimA8ODIpYKwysZxO3xMYxPj1c4QJ/j6YcatEDmFJk6FzImO略

これで多少のことでは破られない…はず。

Ansibleで使う

あとはこれを、ansibleのplaybookにいれます。こんな感じ。

main.yml

- name: adduser(user1)
# password generate via "openssl passwd -6 -salt=$RANDOM "
  user:
    name: user1
    uid: 1001
    state: present
    password: $6$16502$1uE67kAZsw9S06fTsFpOkiZimfT.Dkc6/RHRB8u4TaR4ZPzJWWAL232gy略
    comment: Nanashino Gonbei

以上でございます。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?