0
1

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

【CentOS7】MySQL over SSHの設定をする

Posted at

DomoからDBにアクセスさせたかったのですが、直接アクセスさせるのは少し面倒だったので、SSH経由でアクセスさせるようにした際の設定諸々です。
DomoのMySQL SSH Connectorの設定内容はこちら→MySQL SSH Connector

環境

  • CentOS 7.3
  • MySQL 5.7
  • sshdがインストールされていること

1. ユーザを作成する

アクセスさせるためのユーザを作成します。

$ useradd ユーザ名

2. 公開鍵を作成する

参考:お前らのSSH Keysの作り方は間違っている

既存のSSH Keyの確認

上書きしちゃったりすると危ないので一応確認。

$ ls -al ~/.ssh

デフォルトだと

  • id_rsa.pub

なんかがよく作られてたりする

SSH Keyの作成

  • -Cはメアドだったりサーバ名だったりなんでも。
  • デフォルトのkeyはすでにあったので、ここでは別名で保存
  • パスフレーズはご自由に。
$ ssh-keygen -t rsa -b 4096 -C "xxxxxxxxxxxxxxxxxxx"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): xxxxxxx_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in xxxxxxx_rsa.
Your public key has been saved in xxxxxxx_rsa.pub.
The key fingerprint is:
54:f6:83:62:e6:23:65:dd:a9:99:3a:87:1d:76:14:30 xxxxxxxxxxxxxxxxxxx
The key's randomart image is:
+--[ RSA 4096]----+
|          E..    |
|         + = o   |
|        B o *    |
|       B . = .   |
|      . S * .    |
|       . * o     |
|        + o      |
|         o       |
|                 |
+-----------------+

公開鍵の設置

ログインするユーザのホームディレクトリの配下に公開鍵を置く
.sshフォルダがなければ作ってから。権限周りをしっかり設定しとかないとログインできないらしいので気をつけて!

$ cd /home/(ユーザ名)
$ mkdir .ssh
$ chmod 700 .ssh   # フォルダには700
$ cd .ssh/
$ cat /root/.ssh/xxxxxxx_rsa.pub >> authorized_keys   # rootかログインユーザの配下のsshフォルダに生成されているはずの公開鍵を書き出す
$ chmod 600 authorized_keys   # 鍵は600

公開鍵アクセスの許可

sshd_configの以下の項目のコメントを解除する。
PubkeyAuthenticationはデフォルトだと有効らしい。が、コメントアウトされていたので解除。

$ vi /etc/ssh/sshd_config
# PubkeyAuthentication yes
# AuthorizedKeysFile      .ssh/authorized_keys

3. MySQLにユーザを作る。

もうある方はここらへんは飛ばしてOK
ただし、2019/09/25時点でDomoはSHA256 Passwordには対応してないっぽい?のでパスワードはStandardで作ったほうが良さそう。

コマンド叩くのが面倒だったので、Workbenchで参照のみの権限のユーザを作成しました。(早速SSH経由で接続させた)
くわしくはこちら

user作成1.png
user作成2.png

4. Domoのコネクタに設定内容を記述する

たぶんこんな感じかと。
domoの設定画面.PNG

ちなみに、SSHの設定ができるとMySQL WorkbenchのStandard TCP/IP over SSHでも接続できるようになるので、いろいろ応用はききますね。
鍵の管理はしっかりしないといけないですが。

参考

SSHの公開鍵認証設定をする
SSHの鍵認証設定

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?