MySQLサーバーの強化を行ってみる

スポンサーリンク

VirtualBoxのインストールと、Vagrantをインストールし、CentOS7を動かし、MySQLをインストールしました。今回は、インストールしたMySQLサーバーのセキュリティ問題の強化を行ってみます。

■mysql_secure_installationスクリプトを実行する。

MySQLサーバーのセキュリティ問題の強化を行うために、

[vagrant@localhost ~]$ sudo mysql_secure_installation

sudo権限で、上記のコマンドを入力し、Enterキーを押します。

■rootパスワードを設定

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):

Enterキーを押すと、「Enter current password for root (enter for none):(rootの現在のパスワードを入力(なしの場合は入力):)」と表示されます。今回は、MySQLをインストールしたばかりで、rootのパスワードをまだ設定していませんので、パスワードは空白で入力しますので、Enterキーを押します。

OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n]

Enterキーを押すと、「Set root password? (rootパスワードを設定しますか?)」と質問されます。設定する場合は、「Y」を入力し、Enterキーを押します。今回は設定を行いますので、「Y」を入力しEnterキーを押す。

New password:

Enterキーを押すと、「New password:」と表示されますので、設定するパスワードを入力し、Enterキーを押します。

Re-enter new password:

Enterキーを押すと、新しいパスワードを再入力してくださいと表示されるので、もう1度パスワードを入力し、Enterキーを押します。

■匿名ユーザーを削除

Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]

Enterキーを押すと、rootのパスワードが更新されます。次にデフォルトでは、MySQLは匿名ユーザーが存在し、誰でも許可している状態となっていますので、「匿名ユーザーを削除しますか?」と質問されていますので、削除する場合は「Y」を入力し、Enterキーを押します。今回は削除を行います。

… Success!

「Success!」と表示されますので、これで匿名ユーザーを削除は完了となります。

■リモートでrootログインを制限

Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]

次に、リモートでrootログインを許可するかどうかの質問をされますので、制限・禁止する場合は「Y」を入力し、Enterキーを押します。今回は制限・禁止します。

… Success!

Enterキーを押すと、「Success!」と表示されますので、リモートでrootログインができなくなります。

■「test」という名前のデータベースを削除

By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]

次に、デフォルトでは、MySQLに「test」という名前のデータベースが存在しており、誰でも使用できる状態となっているので、この「test」というデータベースを削除してアクセスするかどうか質問されていますので、削除する場合は、「Y」を入力し、Enterキーを押します。

– Dropping test database…
ERROR 1008 (HY000) at line 1: Can’t drop database ‘test’; database doesn’t exist
… Failed! Not critical, keep moving…
– Removing privileges on test database…
… Success!

Enterキーを押すと、「ERROR 1008 (HY000)」が発生し、「データベース ‘test’を削除できません。」と書かれていますが、「Failed! Not critical, keep moving(失敗しました!重要ではありません、動き続けてください)」とも書かれていますので、このまま続けると、すぐに’test’データベースの権限を削除し、「Success!(成功)」と表示されていますので、’test’権限は削除されました。

■権限テーブルのリロード

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]

次に、権限テーブルをリロードするかどうか質問されます。権限テーブルのリロードを行うと、これまでに行われたすべての変更が確実に行われ、すぐに有効となります。リロードする場合は、「Y」を入力し、Enterキーを押します。今回はリロードを行います。

… Success!

Enterキーを押すと、「Success!」と表示されますので、リロードが行われました。

■セキュリティ問題の強化の完了

All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up…

リロードが完了すると、rootパスワードの設定などのすべての手順を完了しましたというメッセージが表示されますので、これでセキュリティ問題の強化が完了となります。

コメント

タイトルとURLをコピーしました